LCOV - code coverage report
Current view: top level - clients/mapiclient - mhelp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 85 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /**
      10             :  * 2016 Martin Kersten
      11             :  *
      12             :  * The SQL syntax help synopsis.
      13             :  */
      14             : 
      15             : /* produce a synposis of the SQL syntax, inspired by a competing product.
      16             :  * Use the conventional grammar constructs:
      17             :  * [ A | B ]    token A or B or none
      18             :  * { A | B }    exactly one of the options A or B should be chosen
      19             :  * A [',' ...]       a comma separated list of A elements
      20             :  * { A | B } ...     a series of A and B's
      21             :  * { A B } [',' ...] a series of A B,A B,A B,A B
      22             :  *
      23             :  * Ideally each major command line should point into the website for
      24             :  * more details and variations not covered here.
      25             :  * */
      26             : 
      27             : #include "monetdb_config.h"
      28             : #include <ctype.h>
      29             : #include <string.h>
      30             : #ifdef HAVE_STRINGS_H
      31             : #include <strings.h>              /* for strncasecmp */
      32             : #endif
      33             : #include "stream.h"
      34             : #include "mhelp.h"
      35             : 
      36             : typedef struct {
      37             :         const char *command;
      38             :         const char *synopsis;
      39             :         const char *syntax;
      40             :         const char *rules;
      41             :         const char *comments;
      42             : } SQLhelp;
      43             : 
      44             : SQLhelp sqlhelp1[] = {
      45             :         // major commands
      46             :         {"ALTER MERGE TABLE",
      47             :          "",
      48             :          "ALTER TABLE [ IF EXISTS ] qname ADD TABLE qname [ AS PARTITION partition_spec ]\n"
      49             :          "ALTER TABLE [ IF EXISTS ] qname DROP TABLE qname [ RESTRICT | CASCADE ]\n"
      50             :          "ALTER TABLE [ IF EXISTS ] qname SET TABLE qname AS PARTITION partition_spec",
      51             :          "qname,partition_spec",
      52             :          "See also https://www.monetdb.org/Documentation/ServerAdministration/DistributedQueryProcessing/DataPartitioning"},
      53             :         {"ALTER SCHEMA",
      54             :          "",
      55             :          "ALTER SCHEMA [ IF EXISTS ] ident RENAME TO ident",
      56             :          "ident",
      57             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/SchemaDefinitions"},
      58             :         {"ALTER SEQUENCE",
      59             :          "",
      60             :          "ALTER SEQUENCE qname [ AS seq_int_datatype] [ RESTART [WITH intval]] [INCREMENT BY intval]\n"
      61             :          "[MINVALUE intval | NO MINVALUE] [MAXVALUE intval | NO MAXVALUE] [CACHE intval] [[NO] CYCLE]",
      62             :          "seq_int_datatype,intval",
      63             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataTypes/SerialDatatypes"},
      64             :         {"ALTER TABLE",
      65             :          "",
      66             :          "ALTER TABLE [ IF EXISTS ] qname ADD [ COLUMN ] column_def\n"
      67             :          "ALTER TABLE [ IF EXISTS ] qname ADD table_constraint\n"
      68             :          "ALTER TABLE [ IF EXISTS ] qname ALTER [ COLUMN ] ident SET DEFAULT value\n"
      69             :          "ALTER TABLE [ IF EXISTS ] qname ALTER [ COLUMN ] ident SET [NOT] NULL\n"
      70             :          "ALTER TABLE [ IF EXISTS ] qname ALTER [ COLUMN ] ident DROP DEFAULT\n"
      71             :          "ALTER TABLE [ IF EXISTS ] qname ALTER [ COLUMN ] ident SET STORAGE {string | NULL}\n"
      72             :          "ALTER TABLE [ IF EXISTS ] qname DROP [ COLUMN ] ident [ RESTRICT | CASCADE ]\n"
      73             :          "ALTER TABLE [ IF EXISTS ] qname DROP CONSTRAINT ident [ RESTRICT | CASCADE ]\n"
      74             :          "ALTER TABLE [ IF EXISTS ] qname RENAME [ COLUMN ] ident TO ident\n"
      75             :          "ALTER TABLE [ IF EXISTS ] qname RENAME TO ident\n"
      76             :          "ALTER TABLE [ IF EXISTS ] qname SET { INSERT ONLY | READ ONLY | READ WRITE }\n"
      77             :          "ALTER TABLE [ IF EXISTS ] qname SET SCHEMA ident",
      78             :          "qname,column_def,table_constraint,ident",
      79             :          "See also https://www.monetdb.org/Documentation/SQLreference/TableDefinitions/AlterStatement"},
      80             :         {"ALTER USER",
      81             :          "Change a user's login name or password or default schema",
      82             :          "ALTER USER ident RENAME TO ident\n"
      83             :          "ALTER USER SET [ENCRYPTED | UNENCRYPTED] PASSWORD string USING OLD PASSWORD string\n"
      84             :          "ALTER USER ident WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string\n"
      85             :          "ALTER USER ident [WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string] SET SCHEMA ident\n"
      86             :          "ALTER USER ident [WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string] SCHEMA PATH string",
      87             :          "ident",
      88             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/Privileges/Users"},
      89             :         {"ANALYZE",
      90             :          "Collect column/table/schema data statistics for analysis and optimizer usage",
      91             :          "ANALYZE ident [ . ident [ column_list ] ] [SAMPLE size] [MINMAX]",
      92             :          "ident,column_list",
      93             :          "See also https://www.monetdb.org/Documentation/ServerAdministration/TableStatistics"},
      94             :         {"CALL",
      95             :          "Call a stored procedure",
      96             :          "CALL qname '(' [ scalar_expression [',' ...] ] ')' | CALL ident '.' ident",
      97             :          NULL,
      98             :          "See also https://www.monetdb.org/Documentation/SQLreference/Flowofcontrol"},
      99             :         {"COMMENT",
     100             :          "Add, update or remove a comment or description for a database object",
     101             :          "COMMENT ON { SCHEMA | TABLE | VIEW | COLUMN | INDEX | SEQUENCE | function_type }\n"
     102             :          "     qname IS { 'my description text' | NULL | '' }",
     103             :          "function_type,qname",
     104             :          NULL},
     105             :         {"COMMIT",
     106             :          "Commit the current transaction",
     107             :          "COMMIT [ WORK ] [ AND CHAIN | AND NO CHAIN ]",
     108             :          NULL,
     109             :          "See also https://www.monetdb.org/Documentation/SQLreference/Transactions"},
     110             :         {"COPY BINARY",
     111             :          "Append binary representations into a table",
     112             :          "COPY [( BIG | LITTLE | NATIVE) ENDIAN] BINARY INTO qname [column_list] FROM string [',' ...] [ON { CLIENT | SERVER }] [NO CONSTRAINT]",
     113             :          "qname,column_list",
     114             :          "See also https://www.monetdb.org/Documentation/ServerAdministration/LoadingBulkData/BinaryBulkLoad"},
     115             :         {"COPY INTO",
     116             :          "Parse a csv file into a table or write a query result to a csv file",
     117             :          "COPY [nrofrecords] INTO qname [column_list] FROM string [',' ...] [headerlist] [ON { CLIENT | SERVER }] [ separators]\n"
     118             :          " [NULL [AS] string] [LOCKED] [BEST EFFORT] [NO CONSTRAINT] [FWF '(' integer [',' ...] ')'\n"
     119             :          "COPY [nrofrecords] INTO qname [column_list] FROM STDIN [headerlist] [ separators]\n"
     120             :          " [NULL [AS] string] [LOCKED] [BEST EFFORT] [NO CONSTRAINT]\n"
     121             :          "COPY query_expression INTO [STDOUT | string [ON { CLIENT | SERVER }]] [separators] [NULL [AS] string]",
     122             :          "nrofrecords,qname,column_list,headerlist,separators",
     123             :          "See also https://www.monetdb.org/Documentation/ServerAdministration/LoadingBulkData"},
     124             :         {"COPY LOADER",
     125             :          "Copy into using a user supplied parsing function",
     126             :          "COPY LOADER INTO qname FROM qname '(' [ scalar_expression ... ] ')'",
     127             :          "qname,scalar_expression",
     128             :          NULL},
     129             :         {"CREATE AGGREGATE",
     130             :          "Create a user-defined aggregate function. The body of the aggregate function\n"
     131             :          "can also be defined in other programming languages such as Python, R, C or CPP.",
     132             :          "CREATE [ OR REPLACE ] AGGREGATE [ FUNCTION ] qname '(' { '*' | [ param [',' ...]] } ')'\n"
     133             :          "    RETURNS function_return_data_type\n"
     134             :          "    EXTERNAL NAME ident ',' ident\n"
     135             :          "CREATE [ OR REPLACE ] AGGREGATE [ FUNCTION ] qname '(' { '*' | [ param [',' ...]] } ')'\n"
     136             :          "    RETURNS function_return_data_type\n"
     137             :          "    LANGUAGE language_keyword external_code",
     138             :          "qname,param,function_return_data_type,ident,language_keyword,external_code",
     139             :          "See also https://www.monetdb.org/Documentation/SQLreference/ProgrammingSQL/Functions"},
     140             :         {"CREATE FILTER FUNCTION",
     141             :          "Create a user-defined filter function. Currently only MAL definitions\n"
     142             :          "CREATE [ OR REPLACE ] FILTER [ FUNCTION ] qname '(' { '*' | [ param [',' ...]] } ')'\n"
     143             :          "    RETURNS function_return_data_type\n"
     144             :          "    EXTERNAL NAME ident ',' ident",
     145             :          "qname,param,function_return_data_type,ident",
     146             :          "See also https://www.monetdb.org/Documentation/SQLreference/ProgrammingSQL/Functions"},
     147             :         {"CREATE FUNCTION",
     148             :          "Create a user-defined function (UDF). The body of the function can be defined in\n"
     149             :          " PL/SQL or programming languages such as Python, R, C or CPP when embedded on the server.",
     150             :          "CREATE [ OR REPLACE ] FUNCTION qname '(' { '*' | [ param [',' ...]] } ')'\n"
     151             :          "    RETURNS function_return_data_type\n"
     152             :          "    BEGIN [ ATOMIC ] statement [ ';' ...] END\n"
     153             :          "CREATE [ OR REPLACE ] FUNCTION qname '(' { '*' | [ param [',' ...]] } ')'\n"
     154             :          "    RETURNS function_return_data_type\n"
     155             :          "    EXTERNAL NAME ident ',' ident\n"
     156             :          "CREATE [ OR REPLACE ] FUNCTION qname '(' { '*' | [ param [',' ...]] } ')'\n"
     157             :          "    RETURNS function_return_data_type\n"
     158             :          "    LANGUAGE language_keyword external_code",
     159             :          "qname,param,function_return_data_type,statement,ident,language_keyword,external_code",
     160             :          "See also https://www.monetdb.org/Documentation/SQLreference/ProgrammingSQL/Functions"},
     161             :         {"CREATE INDEX",
     162             :          "Create a hint for a secondary index on a column or set of columns of a table",
     163             :          "CREATE [ UNIQUE | ORDERED | IMPRINTS ] INDEX ident ON qname '(' ident_list ')'",
     164             :          NULL,
     165             :          "See also https://www.monetdb.org/Documentation/SQLreference/TableDefinitions/IndexDefinitions"},
     166             :         {"CREATE LOADER",
     167             :          "Create a custom (external) data loader function. The body is defined in Python language",
     168             :          "CREATE [ OR REPLACE ] LOADER [ FUNCTION ] qname '(' [ param [',' ...]] ')'\n"
     169             :          "    LANGUAGE PYTHON external_code",
     170             :          "qname,param,external_code",
     171             :          "See also https://www.monetdb.org/blog/monetdbpython-loader-functions"},
     172             :         {"CREATE MERGE TABLE",
     173             :          "",
     174             :          "CREATE MERGE TABLE [ IF NOT EXISTS ] qname table_source [ partition_by ]",
     175             :          "table_source,partition_by",
     176             :          "See also https://www.monetdb.org/Documentation/ServerAdministration/DistributedQueryProcessing/DataPartitioning"},
     177             :         {"CREATE PROCEDURE",
     178             :          "Create a user-defined procedure",
     179             :          "CREATE [ OR REPLACE ] PROCEDURE qname '(' { '*' | [ param [',' ...]] } ')'\n"
     180             :          "    BEGIN [ ATOMIC ] procedure_statement [ ';' ...] END\n"
     181             :          "CREATE [ OR REPLACE ] PROCEDURE qname '(' { '*' | [ param [',' ...]] } ')'\n"
     182             :          "    EXTERNAL NAME ident ',' ident",
     183             :          "qname,param,procedure_statement,ident",
     184             :          "See also https://www.monetdb.org/Documentation/SQLreference/ProgrammingSQL/Procedures"},
     185             :         {"CREATE REMOTE TABLE",
     186             :          "",
     187             :          "CREATE REMOTE TABLE [ IF NOT EXISTS ] qname ON string [WITH [USER 'username'] [[ENCRYPTED] PASSWORD 'password']]",
     188             :          NULL,
     189             :          "remote name should match mapi:monetdb://host:port/database[/schema[/table]]"},
     190             :         {"CREATE REPLICA TABLE",
     191             :          "",
     192             :          "CREATE REPLICA TABLE [ IF NOT EXISTS ] qname table_source",
     193             :          NULL,
     194             :          "See also https://www.monetdb.org/Documentation/SQLReference/TableDefinitions"},
     195             :         {"CREATE ROLE",
     196             :          "Create a new role. You can grant privileges to a role and next\n"
     197             :          "grant a role (or multiple roles) to specific users",
     198             :          "CREATE ROLE ident [ WITH ADMIN { CURRENT_USER | CURRENT_ROLE } ]",
     199             :          "ident",
     200             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/Privileges/Roles"},
     201             :         {"CREATE SCHEMA",
     202             :          "Create a new schema",
     203             :          "CREATE SCHEMA [ IF NOT EXISTS ] schema_name [default_char_set] [path_spec] [schema_element]",
     204             :          "schema_name,default_char_set,path_spec,schema_element",
     205             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/SchemaDefinitions"},
     206             :         {"CREATE SEQUENCE",
     207             :          "Define a new integer number sequence generator",
     208             :          "CREATE SEQUENCE qname [ AS seq_int_datatype] [ START [WITH intval]] [INCREMENT BY intval]\n"
     209             :          "[MINVALUE intval | NO MINVALUE] [MAXVALUE intval | NO MAXVALUE] [CACHE intval] [[NO] CYCLE]",
     210             :          "seq_int_datatype,intval",
     211             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataTypes/SerialDatatypes"},
     212             :         {"CREATE TABLE",
     213             :          "Create a new table",
     214             :          "CREATE TABLE [ IF NOT EXISTS ] qname table_source [STORAGE ident string]\n"
     215             :          "CREATE TABLE [ IF NOT EXISTS ] qname FROM LOADER function_ref\n"
     216             :          "CREATE [ LOCAL | GLOBAL ] { TEMPORARY | TEMP } TABLE [ IF NOT EXISTS ] qname table_source [on_commit]",
     217             :          "table_source,on_commit,function_ref",
     218             :          "See also https://www.monetdb.org/Documentation/SQLReference/TableDefinitions"},
     219             :         {"CREATE TRIGGER",
     220             :          "Define a triggered action for a table data update event",
     221             :          "CREATE [ OR REPLACE ] TRIGGER ident { BEFORE | AFTER }\n"
     222             :          " { INSERT | DELETE | TRUNCATE | UPDATE [ OF ident_list ] }\n"
     223             :          " ON qname [ REFERENCING trigger_reference [...] ] triggered_action",
     224             :          "qname,ident_list,trigger_reference,triggered_action",
     225             :          "See also https://www.monetdb.org/Documentation/SQLreference/ProgrammingSQL/Triggers"},
     226             :         {"CREATE TYPE",
     227             :          "Add user defined type to the type system ",
     228             :          "CREATE TYPE qname EXTERNAL NAME ident",
     229             :          NULL,
     230             :          NULL},
     231             :         {"CREATE USER",
     232             :          "Create a new database user",
     233             :          "CREATE USER ident WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string NAME string SCHEMA ident [SCHEMA PATH string]",
     234             :          "ident",
     235             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/Privileges/Users"},
     236             :         {"CREATE VIEW",
     237             :          "Create a new view",
     238             :          "CREATE [ OR REPLACE ] VIEW qname [ column_list ] AS { query_expression | '(' query_expression ')' }\n"
     239             :          "[ WITH CHECK OPTION ]",
     240             :          "qname,column_list,query_expression",
     241             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/ViewDefinitions"},
     242             :         {"CREATE WINDOW",
     243             :          "Create a user-defined window function. Currently only MAL definitions\n"
     244             :          "are supported.",
     245             :          "CREATE [ OR REPLACE ] WINDOW [ FUNCTION ] qname '(' { '*' | [ param [',' ...]] } ')'\n"
     246             :          "    RETURNS function_return_data_type\n"
     247             :          "    EXTERNAL NAME ident ',' ident",
     248             :          "qname,param,function_return_data_type,ident",
     249             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataManipulation/WindowFunctions"},
     250             :         {"CURRENT_DATE",
     251             :          "Pseudo column or function to get the current date",
     252             :          "CURRENT_DATE [ '(' ')' ]",
     253             :          NULL,
     254             :          NULL},
     255             :         {"CURRENT_ROLE",
     256             :          "Pseudo column to get the current role name",
     257             :          "CURRENT_ROLE",
     258             :          NULL,
     259             :          NULL},
     260             :         {"CURRENT_SCHEMA",
     261             :          "Pseudo column to get the current schema name",
     262             :          "CURRENT_SCHEMA",
     263             :          NULL,
     264             :          NULL},
     265             :         {"CURRENT_TIME",
     266             :          "Pseudo column or function to get the current time including timezone",
     267             :          "CURRENT_TIME [ '(' ')' ]",
     268             :          NULL,
     269             :          NULL},
     270             :         {"CURRENT_TIMESTAMP",
     271             :          "Pseudo column or function to get the current timestamp including timezone",
     272             :          "CURRENT_TIMESTAMP [ '(' ')' ] | NOW [ '(' ')' ]",
     273             :          NULL,
     274             :          NULL},
     275             :         {"CURRENT_TIMEZONE",
     276             :          "Pseudo column to get the current timezone offset as a second interval",
     277             :          "CURRENT_TIMEZONE",
     278             :          NULL,
     279             :          NULL},
     280             :         {"CURRENT_USER",
     281             :          "Pseudo column to get the current user name",
     282             :          "CURRENT_USER | USER",
     283             :          NULL,
     284             :          NULL},
     285             :         {"DEALLOCATE",
     286             :          "Deallocates a prepared statement or all from the client's session cache",
     287             :          "DEALLOCATE [ PREPARE ] { intnr | ** | ALL }",
     288             :          NULL,
     289             :          NULL},
     290             :         {"DEBUG",
     291             :          "Debug a SQL statement using MAL debugger",
     292             :          "DEBUG statement",
     293             :          NULL,
     294             :          "See also https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/Debug"},
     295             :         {"DECLARE",
     296             :          "Define a local variable",
     297             :          "DECLARE ident_list data_type",
     298             :          "ident_list,data_type",
     299             :          NULL},
     300             :         {"DELETE",
     301             :          "Remove data rows from a table",
     302             :          "[ WITH cte_list ] DELETE FROM qname [ [AS] ident ] [ WHERE search_condition ]",
     303             :          "cte_list,search_condition",
     304             :          NULL},
     305             :         {"DROP AGGREGATE",
     306             :          "",
     307             :          "DROP ALL AGGREGATE [ FUNCTION ] qname [ RESTRICT | CASCADE ]\n"
     308             :          "DROP AGGREGATE [ FUNCTION ] [ IF EXISTS ] qname [ '(' [ param [',' ...]] ')' ] [ RESTRICT | CASCADE ]",
     309             :          "param",
     310             :          NULL},
     311             :         {"DROP FILTER FUNCTION",
     312             :          "",
     313             :          "DROP ALL FILTER [ FUNCTION ] qname [ RESTRICT | CASCADE ]\n"
     314             :          "DROP FILTER [ FUNCTION ] [ IF EXISTS ] qname [ '(' [ param [',' ...]] ')' ] [ RESTRICT | CASCADE ]",
     315             :          "param",
     316             :          NULL},
     317             :         {"DROP FUNCTION",
     318             :          "",
     319             :          "DROP ALL FUNCTION qname [ RESTRICT | CASCADE ]\n"
     320             :          "DROP FUNCTION [ IF EXISTS ] qname [ '(' [ param [',' ...]] ')' ] [ RESTRICT | CASCADE ]",
     321             :          "param",
     322             :          NULL},
     323             :         {"DROP INDEX",
     324             :          "",
     325             :          "DROP INDEX qname",
     326             :          NULL,
     327             :          NULL},
     328             :         {"DROP LOADER",
     329             :          "",
     330             :          "DROP ALL LOADER [ FUNCTION ] qname [ RESTRICT | CASCADE ]\n"
     331             :          "DROP LOADER [ FUNCTION ] [ IF EXISTS ] qname [ '(' [ param [',' ...]] ')' ] [ RESTRICT | CASCADE ]",
     332             :          "param",
     333             :          NULL},
     334             :         {"DROP PROCEDURE",
     335             :          "",
     336             :          "DROP ALL PROCEDURE qname [ RESTRICT | CASCADE ]\n"
     337             :          "DROP PROCEDURE [ IF EXISTS ] qname [ '(' [ param [',' ...]] ')' ] [ RESTRICT | CASCADE ]",
     338             :          "param",
     339             :          NULL},
     340             :         {"DROP ROLE",
     341             :          "",
     342             :          "DROP ROLE ident",
     343             :          NULL,
     344             :          NULL},
     345             :         {"DROP SCHEMA",
     346             :          "",
     347             :          "DROP SCHEMA [ IF EXISTS ] qname [ RESTRICT | CASCADE ]",
     348             :          NULL,
     349             :          NULL},
     350             :         {"DROP SEQUENCE",
     351             :          "",
     352             :          "DROP SEQUENCE qname",
     353             :          NULL,
     354             :          NULL},
     355             :         {"DROP TABLE",
     356             :          "",
     357             :          "DROP TABLE [ IF EXISTS ] qname [ RESTRICT | CASCADE ]",
     358             :          NULL,
     359             :          NULL},
     360             :         {"DROP TRIGGER",
     361             :          "",
     362             :          "DROP TRIGGER [ IF EXISTS ] qname",
     363             :          NULL,
     364             :          NULL},
     365             :         {"DROP TYPE",
     366             :          "",
     367             :          "DROP TYPE qname [ RESTRICT | CASCADE ]",
     368             :          NULL,
     369             :          NULL},
     370             :         {"DROP USER",
     371             :          "",
     372             :          "DROP USER ident",
     373             :          NULL,
     374             :          NULL},
     375             :         {"DROP VIEW",
     376             :          "",
     377             :          "DROP VIEW [ IF EXISTS ] qname [ RESTRICT | CASCADE ]",
     378             :          NULL,
     379             :          NULL},
     380             :         {"DROP WINDOW",
     381             :          "",
     382             :          "DROP ALL WINDOW [ FUNCTION ] qname [ RESTRICT | CASCADE ]\n"
     383             :          "DROP WINDOW [ FUNCTION ] [ IF EXISTS ] qname [ '(' [ param [',' ...]] ')' ] [ RESTRICT | CASCADE ]",
     384             :          "param",
     385             :          NULL},
     386             :         {"EXECUTE",
     387             :          "Execute a prepared SQL statement with supplied parameter values",
     388             :          "EXECUTE { intnr | ** } '(' [ value [, ...] ] ')'",
     389             :          NULL,
     390             :          "See also https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/PrepareExec"},
     391             :         {"EXPLAIN",
     392             :          "Give MAL execution plan for the SQL statement",
     393             :          "EXPLAIN statement",
     394             :          NULL,
     395             :          "See also https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/Explain"},
     396             :         {"EXTRACT",
     397             :          "Built-in function",
     398             :          "EXTRACT '(' { YEAR | MONTH | DAY | HOUR | MINUTE | SECOND | CENTURY | DECADE | QUARTER | WEEK | DOW | DOY | EPOCH } FROM scalar_expression ')'",
     399             :          NULL,
     400             :          NULL},
     401             :         {"INSERT",
     402             :          "Add data rows to a table",
     403             :          "[ WITH cte_list ] INSERT INTO qname [ column_list ]\n"
     404             :          " [ { DEFAULT VALUES | VALUES row_values | query_expression } ]",
     405             :          "cte_list,column_list,row_values,query_expression",
     406             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataManipulation/TableUpdates"},
     407             :         {"GRANT",
     408             :          "Define access privileges",
     409             :          "GRANT privileges TO grantee [',' ...] [ WITH GRANT OPTION ]\n"
     410             :          "GRANT role [',' ...] TO grantee [',' ...] [ WITH ADMIN OPTION]",
     411             :          "privileges,table_privileges,global_privileges,role,grantee",
     412             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/Privileges/GrantAndRevoke"},
     413             :         {"LOCALTIME",
     414             :          "Pseudo column or function to get the current client time excluding timezone",
     415             :          "LOCALTIME [ '(' ')' ]",
     416             :          NULL,
     417             :          NULL},
     418             :         {"LOCALTIMESTAMP",
     419             :          "Pseudo column or function to get the current client timestamp excluding timezone",
     420             :          "LOCALTIMESTAMP [ '(' ')' ]",
     421             :          NULL,
     422             :          NULL},
     423             :         {"MERGE",
     424             :          "",
     425             :          "[ WITH cte_list ] MERGE INTO qname [ [AS] ident ] USING table_ref [ [AS] ident ] ON search_condition merge_list",
     426             :          "cte_list,table_ref,search_condition,merge_list",
     427             :          "See also: https://www.monetdb.org/blog/sql2003_merge_statements_now_supported"},
     428             :         {"PLAN",
     429             :          "Give relational execution plan for the SQL statement",
     430             :          "PLAN statement",
     431             :          NULL,
     432             :          "See also https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/PlanSQL"},
     433             :         {"PREPARE",
     434             :          "Prepare a SQL DML statement with optional question-mark parameter markers",
     435             :          "PREPARE statement",
     436             :          NULL,
     437             :          "See also https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/PrepareExec"},
     438             :         {"RELEASE SAVEPOINT",
     439             :          "",
     440             :          "RELEASE SAVEPOINT ident",
     441             :          NULL,
     442             :          NULL},
     443             :         {"REVOKE",
     444             :          "Remove some privileges",
     445             :          "REVOKE [GRANT OPTION FOR] privileges FROM { grantee [',' ...] | CURRENT_USER | CURRENT_ROLE }\n"
     446             :          "REVOKE [ADMIN OPTION FOR] role [',' ...] FROM { grantee [',' ...] | CURRENT_USER | CURRENT_ROLE }",
     447             :          "privileges,table_privileges,global_privileges,grantee,role",
     448             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataDefinition/Privileges/GrantAndRevoke"},
     449             :         {"ROLLBACK",
     450             :          "Rollback the current transaction",
     451             :          "ROLLBACK [WORK] [ AND CHAIN | AND NO CHAIN ] [TO SAVEPOINT ident]",
     452             :          NULL,
     453             :          "See also https://www.monetdb.org/Documentation/SQLreference/Transactions"},
     454             :         {"SAVEPOINT",
     455             :          NULL,
     456             :          "SAVEPOINT ident",
     457             :          NULL,
     458             :          NULL},
     459             :         {"SELECT",
     460             :          "",
     461             :          "[ WITH cte_list ]\n"
     462             :          "SELECT [ ALL | DISTINCT [ ON { expression [',' ...] } ] ]\n"
     463             :          "[ '*' | expression [ [ AS ] output_name ] [',' ...] ]\n"
     464             :          "[ FROM from_item [',' ...] ]\n"
     465             :          "[ WINDOW window_definition [',' ...] ]\n"
     466             :          "[ WHERE condition ]\n"
     467             :          "[ GROUP BY group_by_element [',' ...] ]\n"
     468             :          "[ HAVING condition [',' ...] ]\n"
     469             :          "[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] [ CORRESPONDING ] select ]\n"
     470             :          "[ ORDER BY expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [',' ...] ]\n"
     471             :          "[ LIMIT { count | param } ]\n"
     472             :          "[ OFFSET { count | param } ]\n"
     473             :          "[ SAMPLE size [ SEED size ] ]",
     474             :          "cte_list,expression,group_by_element,window_definition",
     475             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataManipulation/TableExpressions"},
     476             :         {"SET",
     477             :          "Assign a value to a variable or column",
     478             :          "SET ident '=' simple_atom",
     479             :          "simple_atom",
     480             :          "See also https://www.monetdb.org/Documentation/SQLreference/ProgrammingSQL/Variables"},
     481             :         {"SET LOCAL TRANSACTION",
     482             :          "",
     483             :          "SET LOCAL TRANSACTION [ transactionmode ]",
     484             :          "transactionmode",
     485             :          "See also https://www.monetdb.org/Documentation/SQLreference/SQLSyntaxOverview#SET_LOCAL_TRANSACTION"},
     486             :         {"SET ROLE",
     487             :          "Change current role",
     488             :          "SET ROLE ident",
     489             :          NULL,
     490             :          NULL},
     491             :         {"SET SCHEMA",
     492             :          "Change current schema",
     493             :          "SET SCHEMA ident",
     494             :          NULL,
     495             :          NULL},
     496             :         {"SET SESSION AUTHORIZATION",
     497             :          "",
     498             :          "SET SESSION AUTHORIZATION ident",
     499             :          NULL,
     500             :          NULL},
     501             :         {"SET TIME ZONE",
     502             :          NULL,
     503             :          "SET TIME ZONE interval",
     504             :          "interval",
     505             :          NULL},
     506             :         {"SET TIME ZONE LOCAL",
     507             :          NULL,
     508             :          "SET TIME ZONE LOCAL",
     509             :          NULL,
     510             :          NULL},
     511             :         {"SET TRANSACTION",
     512             :          "",
     513             :          "SET TRANSACTION [ transactionmode ]",
     514             :          "transactionmode",
     515             :          "See also https://www.monetdb.org/Documentation/SQLreference/SQLSyntaxOverview#SET_TRANSACTION"},
     516             :         {"SET USER",
     517             :          "Change current user",
     518             :          "SET USER '=' ident",
     519             :          NULL,
     520             :          NULL},
     521             :         {"START TRANSACTION",
     522             :          "Change transaction mode from auto-commit to user controlled commit/rollback",
     523             :          "{ START | BEGIN } TRANSACTION [ transactionmode ]",
     524             :          "transactionmode",
     525             :          "See also https://www.monetdb.org/Documentation/SQLreference/Transactions"},
     526             :         {"TABLE JOINS",
     527             :          "",
     528             :          "'(' joined_table ') |\n"
     529             :          "table_ref CROSS JOIN table_ref ')' |\n"
     530             :          "table_ref NATURAL [ INNER | LEFT | RIGHT | FULL ] JOIN table_ref |\n"
     531             :          "table_ref UNION JOIN table_ref { ON search_condition | USING column_list } |\n"
     532             :          "table_ref [ INNER | LEFT | RIGHT | FULL ] JOIN table_ref { ON search_condition | USING column_list }",
     533             :          "table_ref,search_condition,column_list",
     534             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataManipulation/TableExpressions"},
     535             :         {"TRACE",
     536             :          "Give execution trace for the SQL statement",
     537             :          "TRACE statement",
     538             :          NULL,
     539             :          "See also https://www.monetdb.org/Documentation/SQLreference/RuntimeFeatures/Trace"},
     540             :         {"TRUNCATE",
     541             :          "Remove all rows from a table",
     542             :          "TRUNCATE [ TABLE ] qname [ CONTINUE IDENTITY | RESTART IDENTITY ] [ CASCADE | RESTRICT ]",
     543             :          "",
     544             :          NULL},
     545             :         {"UPDATE",
     546             :          "Change data in a table",
     547             :          "[ WITH cte_list ] UPDATE qname [ [AS] ident ] SET assignment_list\n"
     548             :          " [ FROM from_item ] [ WHERE search_condition ]",
     549             :          "cte_list,assignment_list,search_condition",
     550             :          NULL},
     551             :         {"VALUES",
     552             :          "Specify a list of row values",
     553             :          "VALUES row_values",
     554             :          "row_values",
     555             :          NULL},
     556             :         {"WINDOW FUNCTIONS",
     557             :          "",
     558             :          "{ window_aggregate_function | window_rank_function } OVER { ident | '(' window_specification ')' }",
     559             :          "window_aggregate_function,window_rank_function,window_specification",
     560             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataManipulation/WindowFunctions"},
     561             :         {NULL, NULL, NULL, NULL, NULL}  /* End of list marker */
     562             : };
     563             : 
     564             : SQLhelp sqlhelp2[] = {
     565             : // The subgrammar rules
     566             :         {"and_exp",
     567             :          NULL,
     568             :          "{ and_exp AND pred_exp | pred_exp }",
     569             :          "pred_exp",
     570             :          NULL},
     571             :         {"assignment_list",
     572             :          NULL,
     573             :          "column '=' DEFAULT | column '=' search_condition | '(' column [',' ...] ')' '=' subquery",
     574             :          "search_condition,column,subquery",
     575             :          NULL},
     576             :         {"authid",
     577             :          NULL,
     578             :          "restricted ident",
     579             :          NULL,
     580             :          NULL},
     581             :         {"case_statement",
     582             :          "Case statement for procedures/functions",
     583             :          "CASE scalar_expression [ when_statement ...]  [ELSE procedure_statement ... ] END CASE",
     584             :          NULL,
     585             :          "See also https://www.monetdb.org/Documentation/SQLreference/Flowofcontrol"},
     586             :         {"column_def",
     587             :          NULL,
     588             :          "ident { data_type [ column_option ... ] | SERIAL | BIGSERIAL }",
     589             :          "ident,data_type,column_option",
     590             :          NULL},
     591             :         {"column_list",
     592             :          NULL,
     593             :          "'(' ident [',' ...] ')'",
     594             :          NULL,
     595             :          NULL},
     596             :         {"column_option",
     597             :          NULL,
     598             :          "DEFAULT value | column_constraint | generated_column",
     599             :          "column_constraint,generated_column",
     600             :          NULL},
     601             :         {"column_option_list",
     602             :          NULL,
     603             :          "ident WITH OPTIONS '(' column_constraint ')' [',' ...]",
     604             :          "column_constraint",
     605             :          NULL},
     606             :         {"column_constraint",
     607             :          NULL,
     608             :          "[ CONSTRAINT ident ] { NOT NULL | NULL | UNIQUE | PRIMARY KEY | CHECK '(' search_condition ')' |\n"
     609             :          "    REFERENCES qname [ column_list ] [ match_options ] [ reference_action ] }\n",
     610             :          "column_list,search_condition,match_options,reference_action",
     611             :          "See also https://www.monetdb.org/Documentation/SQLReference/TableDefinitions/TableIElements"},
     612             :         {"control_statement",
     613             :          NULL,
     614             :          "call_procedure | while_statement | if_statement | case_statement | return_statement",
     615             :          "call_procedure,while_statement,if_statement,case_statement,return_statement",
     616             :          "See also https://www.monetdb.org/Documentation/SQLreference/Flowofcontrol"},
     617             :         {"datetime_type",
     618             :          NULL,
     619             :          "DATE | TIME [ time_precision ] [ WITH TIME ZONE ] |\n"
     620             :          " TIMESTAMP [ timestamp_precision ] [ WITH TIME ZONE ]",
     621             :          "time_precision,timestamp_precision",
     622             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataTypes/TemporalTypes"},
     623             :         {"data_type",
     624             :          NULL,
     625             :          "BOOLEAN | BOOL | TINYINT | SMALLINT | INT | INTEGER | BIGINT | HUGEINT |\n"
     626             :          " { DECIMAL | DEC | NUMERIC | FLOAT } [ '(' nonzero [',' nonzero ] ')' ] |\n"
     627             :          " REAL | DOUBLE [ PRECISION ] |\n"
     628             :          " { VARCHAR | CHARACTER VARYING } '(' nonzero ')' |\n"
     629             :          " { CHAR | CHARACTER [ LARGE OBJECT ] | CLOB | TEXT | STRING | JSON | URL } [ '(' nonzero ')' ] |\n"
     630             :          " { BINARY LARGE OBJECT | BLOB } [ '(' nonzero ')' ] |\n"
     631             :          " UUID | INET | datetime_type | interval_type | geometry_type",
     632             :          "datetime_type,interval_type,geometry_type",
     633             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataTypes"},
     634             :         {"default_char_set",
     635             :          NULL,
     636             :          "DEFAULT CHARACTER SET ident",
     637             :          NULL,
     638             :          NULL},
     639             :         {"drop_table_element",
     640             :          NULL,
     641             :          "{ CONSTRAINT | TABLE | COLUMN } ident [ RESTRICT | CASCADE ]",
     642             :          NULL,
     643             :          NULL},
     644             :         {"end_time",
     645             :          NULL,
     646             :          "SECOND timestamp_precision\n,timestamp_precision",
     647             :          NULL,
     648             :          NULL},
     649             :         {"function_return_data_type",
     650             :          NULL,
     651             :          "data_type | TABLE '(' ident data_type [',' ...] ')'",
     652             :          NULL,
     653             :          NULL},
     654             :         {"function_type",
     655             :          NULL,
     656             :          "{ FUNCTION | PROCEDURE | { { AGGREGATE | FILTER | LOADER | WINDOW } [ FUNCTION ] } }",
     657             :          NULL,
     658             :          NULL},
     659             :         {"generated_column",
     660             :          NULL,
     661             :          "AUTO_INCREMENT | GENERATED ALWAYS AS IDENTITY [ '(' [ AS data_type] [ START [WITH start]] [INCREMENT BY increment]\n"
     662             :          "[MINVALUE minvalue | NO MINVALUE] [MAXVALUE maxvalue | NO MAXVALUE] [CACHE cachevalue] [[NO] CYCLE] ')' ] ",
     663             :          "data_type",
     664             :          "See also https://www.monetdb.org/Documentation/SQLReference/DataTypes/SerialDatatypes"},
     665             :         {"global_privileges",
     666             :          NULL,
     667             :          "{ COPY FROM | COPY INTO } [',' ...]",
     668             :          NULL,
     669             :          NULL},
     670             :         {"grantee",
     671             :          NULL,
     672             :          "{ PUBLIC | authid } ",
     673             :          "authid",
     674             :          NULL},
     675             :         {"group_by_element",
     676             :          NULL,
     677             :          "{ expression | '(' ')' | ROLLUP '(' ident [',' ... ] ')' | CUBE '(' ident [',' ... ] ')'\n"
     678             :          "| GROUPING SETS '(' group_by_element [',' ... ] ')' }",
     679             :          "expression",
     680             :          NULL},
     681             :         {"headerlist",
     682             :          NULL,
     683             :          "'(' { ident [string] } [',' ...] ')'",
     684             :          NULL,
     685             :          NULL},
     686             :         {"ident",
     687             :          "An identifier. Use double quote's around the identifier name to include\n"
     688             :          "        mixed/upper case letters and/or special characters",
     689             :          NULL,
     690             :          NULL,
     691             :          NULL},
     692             :         {"ident_list",
     693             :          NULL,
     694             :          "ident [',' ...]",
     695             :          "ident",
     696             :          NULL},
     697             :         {"if_statement",
     698             :          NULL,
     699             :          "IF search_condition THEN procedure_statement ...\n"
     700             :          "[ELSE IF search_condition THEN procedure_statement ... ]...\n"
     701             :          "[ ELSE procedure_statement ... ] END IF",
     702             :          "search_condition,procedure_statement",
     703             :          "See also https://www.monetdb.org/Documentation/SQLreference/Flowofcontrol"},
     704             :         {"seq_int_datatype",
     705             :          NULL,
     706             :          "BIGINT | INTEGER | INT | SMALLINT | TINYINT",
     707             :          NULL,
     708             :          NULL},
     709             :         {"interval",
     710             :          NULL,
     711             :          "INTERVAL [ '+' | '-' ] string start_field TO end_field",
     712             :          "start_field,end_field",
     713             :          NULL},
     714             :         {"interval_type",
     715             :          NULL,
     716             :          "INTERVAL { YEAR | MONTH | DAY | HOUR | MINUTE | SECOND [time_precision] | start_field TO end_field }",
     717             :          "time_precision,start_field,end_field",
     718             :          NULL},
     719             :         {"intval",
     720             :          "Integer value",
     721             :          NULL,
     722             :          NULL,
     723             :          NULL},
     724             :         {"isolevel",
     725             :          NULL,
     726             :          "READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE",
     727             :          NULL,
     728             :          NULL},
     729             :         {"language_keyword",
     730             :          NULL,
     731             :          "C | CPP | R | PYTHON | PYTHON_MAP | PYTHON3 | PYTHON3_MAP",
     732             :          NULL,
     733             :          NULL},
     734             :         {"match_options",
     735             :          NULL,
     736             :          "MATCH { FULL | PARTIAL | SIMPLE }",
     737             :          NULL,
     738             :          NULL},
     739             :         {"merge_list",
     740             :          NULL,
     741             :          "merge_clause [ merge_clause ]",
     742             :          "merge_clause",
     743             :          NULL},
     744             :         {"merge_clause",
     745             :          NULL,
     746             :          "{ WHEN NOT MATCHED THEN INSERT [ column_list ] [ { VALUES row_values | DEFAULT VALUES } ]\n"
     747             :          "| WHEN MATCHED THEN { UPDATE SET assignment_list | DELETE } }",
     748             :          "column_list,row_values,assignment_list",
     749             :          NULL},
     750             :         {"nrofrecords",
     751             :          NULL,
     752             :          "OFFSET integer | integer RECORDS | integer OFFSET integer RECORDS | integer RECORDS OFFSET integer",
     753             :          NULL,
     754             :          NULL},
     755             :         {"on_commit",
     756             :          NULL,
     757             :          "ON COMMIT { DELETE ROWS | PRESERVE ROWS | DROP }",
     758             :          NULL,
     759             :          NULL},
     760             :         {"partition_by",
     761             :          NULL,
     762             :          "PARTITION BY { RANGE | VALUES } { ON '(' ident ')' | USING '(' query_expression ')' }",
     763             :          "query_expression",
     764             :          "See also: https://www.monetdb.org/blog/updatable-merge-tables"},
     765             :         {"partition_spec",
     766             :          NULL,
     767             :          "{ IN '(' partition_list ')' [ WITH NULL VALUES ]\n"
     768             :          "| FROM partition_range_from TO partition_range_to [ WITH NULL VALUES ]\n"
     769             :          "| FOR NULL VALUES }",
     770             :          "partition_list,partition_range_from,partition_range_to",
     771             :          "See also: https://www.monetdb.org/blog/updatable-merge-tables"},
     772             :         {"param",
     773             :          NULL,
     774             :          "ident data_type",
     775             :          NULL,
     776             :          NULL},
     777             :         {"partition_list",
     778             :          NULL,
     779             :          "query_expression [',' ...]",
     780             :          "query_expression",
     781             :          NULL},
     782             :         {"partition_range_from",
     783             :          NULL,
     784             :          "{ RANGE MINVALUE | query_expression }",
     785             :          "query_expression",
     786             :          NULL},
     787             :         {"partition_range_to",
     788             :          NULL,
     789             :          "{ RANGE MAXVALUE | query_expression }",
     790             :          "query_expression",
     791             :          NULL},
     792             :         {"pred_exp",
     793             :          NULL,
     794             :          "{ NOT pred_exp | predicate }",
     795             :          "predicate",
     796             :          NULL},
     797             :         {"predicate",
     798             :          NULL,
     799             :          "comparison_predicate | between_predicate | like_predicate | test_for_null | in_predicate | all_or_any_predicate | existence_test | filter_exp | scalar_exp",
     800             :          NULL,
     801             :          NULL},
     802             :         {"privileges",
     803             :          NULL,
     804             :          "table_privileges | EXECUTE ON function_type qname | global_privileges",
     805             :          "function_type,table_privileges,global_privileges",
     806             :          NULL},
     807             :         {"procedure_statement",
     808             :          NULL,
     809             :          "{ update_statement | declare_statement | set_statement | control_statement | select_single_row } ';'",
     810             :          "update_statement,declare_statement,set_statement,control_statement,select_single_row",
     811             :          NULL},
     812             :         {"select_single_row",
     813             :          NULL,
     814             :          "SELECT [ ALL | DISTINCT ] column_exp_commalist INTO select_target_list [ from_clause ] [ window_clause ] [ where_clause ] [ group_by_clause ] [ having_clause ]",
     815             :          "column_exp_commalist,select_target_list,from_clause,window_clause,where_clause,group_by_clause,having_clause",
     816             :          NULL},
     817             :         {"query_expression",
     818             :          NULL,
     819             :          "select_no_parens [ order_by_clause ] [ limit_clause ] [ offset_clause ] [ sample_clause ]",
     820             :          "select_no_parens,order_by_clause,limit_clause,offset_clause,sample_clause",
     821             :          NULL},
     822             :         {"select_no_parens",
     823             :          NULL,
     824             :          "{ SELECT [ ALL | DISTINCT ] column_exp_commalist [ from_clause ] [ window_clause ] [ where_clause ] [ group_by_clause ] [ having_clause ]\n"
     825             :          "| select_no_parens { UNION | EXCEPT | INTERSECT } [ ALL | DISTINCT ] [ corresponding ] select_no_parens\n"
     826             :          "| '(' select_no_parens ')' }",
     827             :          "column_exp_commalist,from_clause,window_clause,where_clause,group_by_clause,having_clause,corresponding",
     828             :          NULL},
     829             :         {"corresponding",
     830             :          NULL,
     831             :          "{ CORRESPONDING | CORRESPONDING BY '(' column_ref_commalist ')' }",
     832             :          "column_ref_commalist",
     833             :          NULL},
     834             :         {"qname",
     835             :          NULL,
     836             :          "ident [ '.' ident ['.' ident]]",
     837             :          NULL,
     838             :          NULL},
     839             :         {"reference_action",
     840             :          NULL,
     841             :          "ON { UPDATE | DELETE } { NO ACTION | CASCADE | RESTRICT | SET NULL | SET DEFAULT }",
     842             :          NULL,
     843             :          NULL},
     844             :         {"return_statement",
     845             :          "",
     846             :          "RETURN { query_expression | search_condition | TABLE '(' query_expression ')' | NULL }",
     847             :          "query_expression,search_condition",
     848             :          NULL},
     849             :         {"row_values",
     850             :          NULL,
     851             :          "'(' atom [ ',' atom ]... ')' [ ',' row_values ] ...",
     852             :          "atom",
     853             :          NULL},
     854             :         {"schema_name",
     855             :          NULL,
     856             :          "ident | [ident] AUTHORIZATION authorization_ident",
     857             :          NULL,
     858             :          NULL},
     859             :         {"schema_element",
     860             :          NULL,
     861             :          "grant | revoke | create_statement | drop_statement | alter_statement",
     862             :          NULL,
     863             :          NULL},
     864             :         {"search_condition",
     865             :          NULL,
     866             :          "{ search_condition OR and_exp | and_exp }",
     867             :          "and_exp",
     868             :          NULL},
     869             :         {"separators",
     870             :          NULL,
     871             :          "[USING] DELIMITERS field_sep_string [',' record_sep_string [',' quote_string]]",
     872             :          NULL,
     873             :          NULL},
     874             :         {"split_part",
     875             :          NULL,
     876             :          "SPLIT_PART '(' string ',' delimiter_string ',' field_index ')'",
     877             :          NULL,
     878             :          NULL,},
     879             :         {"table_constraint",
     880             :          NULL,
     881             :          "[ CONSTRAINT ident ] { PRIMARY KEY column_list | UNIQUE column_list |\n"
     882             :          "    FOREIGN KEY column_list REFERENCES qname [ column_list ] [ match_options ] [ reference_action ] }",
     883             :          "column_list,match_options,reference_action",
     884             :          "See also https://www.monetdb.org/Documentation/SQLReference/TableDefinitions/TableIElements"},
     885             :         {"table_element",
     886             :          NULL,
     887             :          "column_def | table_constraint | column_option_list | LIKE qname",
     888             :          "column_def,table_constraint,column_option_list",
     889             :          NULL},
     890             :         {"table_name",
     891             :          NULL,
     892             :          "[AS] ident ['(' name [',' ...] ')' ]",
     893             :          NULL,
     894             :          NULL},
     895             :         {"table_privileges",
     896             :          NULL,
     897             :          "{ ALL [ PRIVILEGES ] | INSERT | DELETE | TRUNCATE\n"
     898             :          "| { SELECT | UPDATE | REFERENCES } [ column_list ] } [',' ...] ON [ TABLE ] qname",
     899             :          "column_list",
     900             :          NULL},
     901             :         {"table_ref",
     902             :          NULL,
     903             :          "[LATERAL] func_ref [table_name] | [LATERAL] subquery | joined_table",
     904             :          "table_name,subquery",
     905             :          NULL},
     906             :         {"table_source",
     907             :          NULL,
     908             :          "'(' table_element [',' ...] ')' | column_list AS query_expression [ WITH [NO] DATA ] ",
     909             :          "table_element,column_list,query_expression",
     910             :          NULL},
     911             :         {"transaction_statement",
     912             :          NULL,
     913             :          "commit | savepoint | release | rollback | start transaction | set local transaction",
     914             :          "commit,savepoint,release,rollback,start transaction,set local transaction",
     915             :          NULL},
     916             :         {"time_precision",
     917             :          NULL,
     918             :          "'(' integer ')'",
     919             :          NULL,
     920             :          NULL},
     921             :         {"timestamp_precision",
     922             :          NULL,
     923             :          "'(' integer ')'",
     924             :          NULL,
     925             :          NULL},
     926             :         {"transactionmode",
     927             :          NULL,
     928             :          "{ READ ONLY | READ WRITE | ISOLATION LEVEL isolevel | DIAGNOSTICS intval } [ , ... ]",
     929             :          "isolevel",
     930             :          "Note: DIAGNOSTICS is not yet implemented"},
     931             :         {"trigger_reference",
     932             :          NULL,
     933             :          "{ OLD | NEW } { [ROW] | TABLE } [AS] ident",
     934             :          NULL,
     935             :          NULL},
     936             :         {"update_statement",
     937             :          NULL,
     938             :          "delete_stmt | truncate_stmt | insert_stmt | update_stmt | merge_stmt | copyfrom_stmt",
     939             :          "delete_stmt,truncate_stmt,insert_stmt,update_stmt,merge_stmt,copyfrom_stmt",
     940             :          NULL},
     941             :         {"triggered_action",
     942             :          NULL,
     943             :          "[ FOR [EACH] { ROW | STATEMENT } ]\n"
     944             :          "[ WHEN '(' search_condition ')' ]\n"
     945             :          "{ trigger_statement | BEGIN ATOMIC trigger_statement [ ; ... ] END }",
     946             :          "trigger_statement,search_condition",
     947             :          NULL},
     948             :         {"trigger_statement",
     949             :          NULL,
     950             :          "update_statement | declare_statement | set_statement | control_statement | select_single_row",
     951             :          "update_statement,declare_statement,set_statement,control_statement,select_single_row",
     952             :          NULL},
     953             :         {"when_statement",
     954             :          NULL,
     955             :          "WHEN scalar_expression THEN procedure_statement ...",
     956             :          "procedure_statement",
     957             :          NULL},
     958             :         {"while_statement",
     959             :          NULL,
     960             :          "[ident ':'] WHILE search_condition DO procedure_statement ... END WHILE [ident]",
     961             :          "search_condition,procedure_statement",
     962             :          "See also https://www.monetdb.org/Documentation/SQLreference/Flowofcontrol"},
     963             :         {"window_aggregate_function",
     964             :          NULL,
     965             :          "{ AVG '(' query_expression ')' | COUNT '(' { '*' | query_expression } ')' | MAX '(' query_expression ')'\n"
     966             :          "| MIN '(' query_expression ')' | PROD '(' query_expression ')' | SUM '(' query_expression ')' }",
     967             :          "query_expression",
     968             :          NULL},
     969             :         {"window_bound",
     970             :          NULL,
     971             :          "{ UNBOUNDED FOLLOWING | query_expression FOLLOWING | UNBOUNDED PRECEDING | query_expression PRECEDING | CURRENT ROW }",
     972             :          "query_expression",
     973             :          NULL},
     974             :         {"window_definition",
     975             :          NULL,
     976             :          "ident AS '(' window_specification ')'",
     977             :          "window_specification",
     978             :          NULL},
     979             :         {"window_frame_start",
     980             :          NULL,
     981             :          "{ UNBOUNDED PRECEDING | query_expression PRECEDING | CURRENT ROW }",
     982             :          "query_expression",
     983             :          NULL},
     984             :         {"window_rank_function",
     985             :          NULL,
     986             :          "{ CUME_DIST '(' ')' | DENSE_RANK '(' ')' | FIRST_VALUE '(' query_expression ')'\n"
     987             :          "| LAG '(' query_expression [ ',' query_expression [ ',' query_expression ] ] ')' | LAST_VALUE '(' query_expression ')'\n"
     988             :          "| LEAD '(' query_expression [ ',' query_expression [ ',' query_expression ] ] ')'\n"
     989             :          "| NTH_VALUE '(' query_expression ',' query_expression ')' | NTILE '(' query_expression ')'\n"
     990             :          "| PERCENT_RANK '(' ')' | RANK '(' ')' | ROW_NUMBER '(' ')' }",
     991             :          "query_expression",
     992             :          NULL},
     993             :         {"window_specification",
     994             :          NULL,
     995             :          "[ ident ]\n"
     996             :          "[ PARTITION BY expression [',' ...] ]\n"
     997             :          "[ ORDER BY expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [',' ...] ]\n"
     998             :          "[ { ROWS | RANGE | GROUPS } { window_frame_start | BETWEEN window_bound AND window_bound }\n"
     999             :          "  [ EXCLUDING { CURRENT ROW | GROUP | TIES | NO OTHERS } ] ]",
    1000             :          "window_bound,window_frame_start",
    1001             :          NULL},
    1002             :         {"cte_list",
    1003             :          NULL,
    1004             :          "ident [ column_list ] AS query_expression [ ',' cte_list ] ...",
    1005             :          "column_list,query_expression",
    1006             :          NULL},
    1007             :         {NULL, NULL, NULL, NULL, NULL}  /* End of list marker */
    1008             : };
    1009             : 
    1010             : static const char *
    1011           0 : sql_grammar_rule(const char *word, stream *toConsole)
    1012             : {
    1013             :         char buf[65], *s = buf;
    1014             :         int i;
    1015           0 :         while (s < buf + 64 && *word != ',' && *word && !isspace((unsigned char) *word))
    1016           0 :                 *s++ = *word++;
    1017           0 :         *s = 0;
    1018             : 
    1019           0 :         for (i = 0; sqlhelp2[i].command; i++) {
    1020           0 :                 if (strcasecmp(sqlhelp2[i].command, buf) == 0) {
    1021           0 :                         if (sqlhelp2[i].syntax) {
    1022           0 :                                 mnstr_printf(toConsole, "%s : %s\n", buf, sqlhelp2[i].syntax);
    1023           0 :                                 if (sqlhelp2[i].synopsis)
    1024           0 :                                         mnstr_printf(toConsole, "%.*s   %s\n", (int) (s - buf), "", sqlhelp2[i].synopsis);
    1025           0 :                         } else if (sqlhelp2[i].synopsis)
    1026           0 :                                 mnstr_printf(toConsole, "%s : %s\n", buf, sqlhelp2[i].synopsis);
    1027             :                 }
    1028             :         }
    1029           0 :         while (*word && (isalnum((unsigned char) *word || *word == '_')))
    1030           0 :                 word++;
    1031           0 :         while (*word && isspace((unsigned char) *word))
    1032           0 :                 word++;
    1033           0 :         return *word == ',' ? word + 1 : NULL;
    1034             : }
    1035             : 
    1036             : static void
    1037           0 : sql_grammar(SQLhelp *sqlhelp, stream *toConsole)
    1038             : {
    1039             :         const char *t1;
    1040           0 :         if (sqlhelp->synopsis == NULL) {
    1041           0 :                 mnstr_printf(toConsole, "%s : %s\n", sqlhelp->command, sqlhelp->syntax);
    1042           0 :                 if (sqlhelp->comments)
    1043           0 :                         mnstr_printf(toConsole, "%s\n", sqlhelp->comments);
    1044           0 :                 t1 = sqlhelp->rules;
    1045           0 :                 if (t1 && *t1)
    1046             :                         do
    1047           0 :                                 t1 = sql_grammar_rule(t1, toConsole);
    1048           0 :                         while (t1);
    1049           0 :                 return;
    1050             :         }
    1051           0 :         if (sqlhelp->command)
    1052           0 :                 mnstr_printf(toConsole, "command  : %s\n", sqlhelp->command);
    1053           0 :         if (sqlhelp->synopsis && *sqlhelp->synopsis)
    1054           0 :                 mnstr_printf(toConsole, "synopsis : %s\n", sqlhelp->synopsis);
    1055           0 :         if (sqlhelp->syntax && *sqlhelp->syntax) {
    1056           0 :                 mnstr_printf(toConsole, "syntax   : ");
    1057           0 :                 for (t1 = sqlhelp->syntax; *t1; t1++) {
    1058           0 :                         if (*t1 == '\n')
    1059           0 :                                 mnstr_printf(toConsole, "\n           ");
    1060             :                         else
    1061           0 :                                 mnstr_printf(toConsole, "%c", *t1);
    1062             :                 }
    1063           0 :                 mnstr_printf(toConsole, "\n");
    1064           0 :                 t1 = sqlhelp->rules;
    1065           0 :                 if (t1 && *t1)
    1066             :                         do
    1067           0 :                                 t1 = sql_grammar_rule(t1, toConsole);
    1068           0 :                         while (t1);
    1069             :         }
    1070           0 :         if (sqlhelp->comments)
    1071           0 :                 mnstr_printf(toConsole, "%s\n", sqlhelp->comments);
    1072             : }
    1073             : 
    1074             : static void
    1075           0 : sql_word(const char *word, size_t maxlen, stream *toConsole)
    1076             : {
    1077             :         size_t i;
    1078             : 
    1079           0 :         mnstr_printf(toConsole, "%s", word);
    1080           0 :         for (i = strlen(word); i <= maxlen; i++)
    1081           0 :                 mnstr_printf(toConsole, " ");
    1082           0 : }
    1083             : 
    1084             : void
    1085           0 : sql_help(const char *pattern, stream *toConsole, int pagewidth)
    1086             : {
    1087             :         size_t maxlen = 1, len;
    1088             :         int i, step, ncolumns, total = 0;
    1089             : 
    1090           0 :         if (*pattern == '\\')
    1091           0 :                 pattern++;
    1092           0 :         while (*pattern && !isspace((unsigned char) *pattern)) {
    1093           0 :                 pattern++;
    1094             :         }
    1095           0 :         while (*pattern && isspace((unsigned char) *pattern)) {
    1096           0 :                 pattern++;
    1097             :         }
    1098             : 
    1099           0 :         if (*pattern && *pattern != '*') {
    1100             :                 bool first = true;
    1101           0 :                 size_t patlen = strlen(pattern);
    1102             :                 /* ignore possible final newline in pattern */
    1103           0 :                 if (pattern[patlen - 1] == '\n')
    1104             :                         patlen--;
    1105           0 :                 for (i = 0; sqlhelp1[i].command; i++)
    1106           0 :                         if (strncasecmp(sqlhelp1[i].command, pattern, patlen) == 0) {
    1107           0 :                                 if (!first)
    1108           0 :                                         mnstr_printf(toConsole, "\n");
    1109           0 :                                 sql_grammar(&sqlhelp1[i], toConsole);
    1110             :                                 first = false;
    1111             :                         }
    1112           0 :                 for (i = 0; sqlhelp2[i].command; i++)
    1113           0 :                         if (strncasecmp(sqlhelp2[i].command, pattern, patlen) == 0) {
    1114           0 :                                 if (!first)
    1115           0 :                                         mnstr_printf(toConsole, "\n");
    1116           0 :                                 sql_grammar(&sqlhelp2[i], toConsole);
    1117             :                                 first = false;
    1118             :                         }
    1119             :                 return;
    1120             :         }
    1121             : 
    1122             :         // collect the major topics
    1123           0 :         for (i = 0; sqlhelp1[i].command; i++) {
    1124           0 :                 total++;
    1125           0 :                 if ((len = strlen(sqlhelp1[i].command)) > maxlen)
    1126             :                         maxlen = len;
    1127             :         }
    1128             :         // provide summary of all major topics  (=search terms)
    1129           0 :         ncolumns = (int) maxlen > pagewidth ? 1 : (int) (pagewidth / maxlen);
    1130           0 :         if (ncolumns > 1 && ncolumns * (int) maxlen + ncolumns - 1 > pagewidth)
    1131           0 :                 ncolumns--;
    1132           0 :         step = total / ncolumns;
    1133           0 :         if(total % ncolumns) {
    1134           0 :                 step++;
    1135             :         }
    1136           0 :         for (i = 0; i < step; i++) {
    1137           0 :                 for (int j = 0; j < ncolumns; j++) {
    1138           0 :                         size_t nextNum = i + j * step;
    1139           0 :                         if(nextNum < sizeof(sqlhelp1)/sizeof(sqlhelp1[0]) - 1) {
    1140           0 :                                 sql_word(sqlhelp1[nextNum].command, j < ncolumns - 1 ? maxlen : 0, toConsole);
    1141             :                         }
    1142             :                 }
    1143           0 :                 mnstr_printf(toConsole, "\n");
    1144             :         }
    1145           0 :         mnstr_printf(toConsole,
    1146             :                 "Using the conventional grammar constructs:\n"
    1147             :                 "[ A | B ]    token A or B or none\n"
    1148             :                 "{ A | B }    exactly one of the options A or B should be chosen\n"
    1149             :                 "A [',' ...]       a comma separated list of A elements\n"
    1150             :                 "{ A | B } ...     a series of A and B's\n"
    1151             :                 "{ A B } [',' ...] a series of A B,A B,A B,A B\n"
    1152             :                 "For more search terms type: \\help *\n"
    1153             :                 "See also https://www.monetdb.org/Documentation/SQLreference\n");
    1154             : }

Generated by: LCOV version 1.14