1 /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.295 2004/08/28 18:04:51 tgl Exp $ */
3 /* Copyright comment */
5 #include "postgres_fe.h"
10 * Variables containing simple states.
13 int braces_open; /* brace level counter */
14 int ecpg_informix_var = 0;
15 char *connection = NULL;
16 char *input_filename = NULL;
18 static int QueryIsRule = 0, FoundInto = 0;
19 static int initializer = 0;
20 static struct this_type actual_type[STRUCT_DEPTH];
21 static char *actual_startline[STRUCT_DEPTH];
23 /* temporarily store struct members while creating the data structure */
24 struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH] = { NULL };
26 /* also store struct type so we can do a sizeof() later */
27 static char *ECPGstruct_sizeof = NULL;
29 /* for forward declarations we have to store some data as well */
30 static char *forward_name = NULL;
32 struct ECPGtype ecpg_no_indicator = {ECPGt_NO_INDICATOR, 0L, NULL, {NULL}};
33 struct variable no_indicator = {"no_indicator", &ecpg_no_indicator, 0, NULL};
35 struct ECPGtype ecpg_query = {ECPGt_char_variable, 0L, NULL, {NULL}};
37 static struct inf_compat_col
41 struct inf_compat_col *next;
44 static struct inf_compat_val
47 struct inf_compat_val *next;
51 * Handle parsing errors and warnings
54 mmerror(int error_code, enum errortype type, char * error, ...)
58 fprintf(stderr, "%s:%d: ", input_filename, yylineno);
63 fprintf(stderr, "WARNING: ");
67 fprintf(stderr, "ERROR: ");
72 vfprintf(stderr, error, ap);
75 fprintf(stderr, "\n");
82 ret_value = error_code;
90 * string concatenation
94 cat2_str(char *str1, char *str2)
96 char * res_str = (char *)mm_alloc(strlen(str1) + strlen(str2) + 2);
98 strcpy(res_str, str1);
100 strcat(res_str, str2);
107 cat_str(int count, ...)
113 va_start(args, count);
115 res_str = va_arg(args, char *);
117 /* now add all other strings */
118 for (i = 1; i < count; i++)
119 res_str = cat2_str(res_str, va_arg(args, char *));
127 make_str(const char *str)
129 char * res_str = (char *)mm_alloc(strlen(str) + 1);
131 strcpy(res_str, str);
136 make2_str(char *str1, char *str2)
138 char * res_str = (char *)mm_alloc(strlen(str1) + strlen(str2) + 1);
140 strcpy(res_str, str1);
141 strcat(res_str, str2);
148 make3_str(char *str1, char *str2, char *str3)
150 char * res_str = (char *)mm_alloc(strlen(str1) + strlen(str2) +strlen(str3) + 1);
152 strcpy(res_str, str1);
153 strcat(res_str, str2);
154 strcat(res_str, str3);
165 char * name = (char *)mm_alloc(yyleng + 1);
167 strncpy(name, yytext, yyleng);
173 create_questionmarks(char *name, bool array)
175 struct variable *p = find_variable(name);
177 char *result = EMPTY;
179 /* In case we have a struct, we have to print as many "?" as there are attributes in the struct
180 * An array is only allowed together with an element argument
181 * This is essantially only used for inserts, but using a struct as input parameter is an error anywhere else
182 * so we don't have to worry here. */
184 if (p->type->type == ECPGt_struct || (array && p->type->type == ECPGt_array && p->type->u.element->type == ECPGt_struct))
186 struct ECPGstruct_member *m;
188 if (p->type->type == ECPGt_struct)
189 m = p->type->u.members;
191 m = p->type->u.element->u.members;
193 for (count = 0; m != NULL; m=m->next, count++);
198 for (; count > 0; count --)
199 result = cat2_str(result, make_str("? , "));
201 /* removed the trailing " ," */
203 result[strlen(result)-3] = '\0';
208 adjust_informix(struct arguments *list)
210 /* Informix accepts DECLARE with variables that are out of scope when OPEN is called.
211 * This breaks standard and leads to some very dangerous programming.
212 * Since they do, we have to work around and accept their syntax as well.
213 * But we will do so ONLY in Informix mode.
214 * We have to change the variables to our own struct and just store the pointer instead of the variable */
216 struct arguments *ptr;
217 char *result = make_str("");
219 for (ptr = list; ptr != NULL; ptr = ptr->next)
221 char temp[20]; /* this should be sufficient unless you have 8 byte integers */
224 /* change variable name to "ECPG_informix_get_var(<counter>)" */
225 original_var = ptr->variable->name;
226 sprintf(temp, "%d))", ecpg_informix_var);
228 if ((ptr->variable->type->type != ECPGt_char && ptr->variable->type->type != ECPGt_unsigned_char) && atoi(ptr->variable->type->size) > 1)
230 ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->variable->type->u.element->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable->type->u.element->type, make_str("1")), ptr->variable->type->size), 0);
231 sprintf(temp, "%d, (", ecpg_informix_var++);
235 ptr->variable = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size), 0);
236 sprintf(temp, "%d, &(", ecpg_informix_var++);
239 /* create call to "ECPG_informix_set_var(<counter>, <pointer>. <linen number>)" */
240 result = cat_str(5, result, make_str("ECPG_informix_set_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
242 /* now the indicator if there is one */
243 if (ptr->indicator->type->type != ECPGt_NO_INDICATOR)
245 /* change variable name to "ECPG_informix_get_var(<counter>)" */
246 original_var = ptr->indicator->name;
247 sprintf(temp, "%d))", ecpg_informix_var);
249 /* create call to "ECPG_informix_set_var(<counter>, <pointer>. <linen number>)" */
250 if (atoi(ptr->indicator->type->size) > 1)
252 ptr->indicator = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->indicator->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size), 0);
253 sprintf(temp, "%d, (", ecpg_informix_var++);
257 ptr->indicator = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->indicator->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size), 0);
258 sprintf(temp, "%d, &(", ecpg_informix_var++);
260 result = cat_str(5, result, make_str("ECPG_informix_set_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
267 static struct cursor *
268 add_additional_variables(char *name, bool insert)
273 for (ptr = cur; ptr != NULL; ptr=ptr->next)
275 if (strcmp(ptr->name, name) == 0)
281 mmerror(PARSE_ERROR, ET_ERROR, "trying to access an undeclared cursor %s\n", name);
286 /* add all those input variables that were given earlier
287 * note that we have to append here but have to keep the existing order */
288 for (p = ptr->argsinsert; p; p = p->next)
289 add_variable_to_tail(&argsinsert, p->variable, p->indicator);
292 /* add all those output variables that were given earlier */
293 for (p = ptr->argsresult; p; p = p->next)
294 add_variable_to_tail(&argsresult, p->variable, p->indicator);
307 struct this_type type;
308 enum ECPGttype type_enum;
309 enum ECPGdtype dtype_enum;
310 struct fetch_desc descriptor;
311 struct su_symbol struct_union;
314 /* special embedded SQL token */
315 %token SQL_ALLOCATE SQL_AUTOCOMMIT SQL_BOOL SQL_BREAK
316 SQL_CALL SQL_CARDINALITY SQL_CONNECT SQL_CONNECTION
317 SQL_CONTINUE SQL_COUNT SQL_CURRENT SQL_DATA
318 SQL_DATETIME_INTERVAL_CODE
319 SQL_DATETIME_INTERVAL_PRECISION SQL_DESCRIBE
320 SQL_DESCRIPTOR SQL_DISCONNECT SQL_ENUM SQL_FOUND
321 SQL_FREE SQL_GO SQL_GOTO SQL_IDENTIFIED
322 SQL_INDICATOR SQL_KEY_MEMBER SQL_LENGTH
323 SQL_LONG SQL_NAME SQL_NULLABLE SQL_OCTET_LENGTH
324 SQL_OPEN SQL_OUTPUT SQL_RELEASE SQL_REFERENCE
325 SQL_RETURNED_LENGTH SQL_RETURNED_OCTET_LENGTH SQL_SCALE
326 SQL_SECTION SQL_SHORT SQL_SIGNED SQL_SQL SQL_SQLERROR
327 SQL_SQLPRINT SQL_SQLWARNING SQL_START SQL_STOP
328 SQL_STRUCT SQL_UNSIGNED SQL_VALUE SQL_VAR SQL_WHENEVER
331 %token S_ADD S_AND S_ANYTHING S_AUTO S_CONST S_DEC S_DIV
332 S_DOTPOINT S_EQUAL S_EXTERN S_INC S_LSHIFT S_MEMPOINT
333 S_MEMBER S_MOD S_MUL S_NEQUAL S_OR S_REGISTER S_RSHIFT
334 S_STATIC S_SUB S_VOLATILE
337 /* I need this and don't know where it is defined inside the backend */
340 /* ordinary key words in alphabetical order */
341 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD AFTER
342 AGGREGATE ALL ALSO ALTER ANALYSE ANALYZE AND ANY ARRAY AS ASC
343 ASSERTION ASSIGNMENT AT AUTHORIZATION
345 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
348 CACHE CALLED CASCADE CASE CAST CHAIN CHAR_P
349 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
350 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
351 COMMITTED CONSTRAINT CONSTRAINTS CONVERSION_P CONVERT COPY
352 CREATE CREATEDB CREATEUSER CROSS CSV CURRENT_DATE CURRENT_TIME
353 CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
355 DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
356 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS
357 DESC DISTINCT DO DOMAIN_P DOUBLE_P DROP
358 EACH ELSE ENCODING ENCRYPTED END_P ESCAPE EXCEPT EXCLUSIVE EXCLUDING
359 EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
361 FALSE_P FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD FREEZE FROM
364 GET GLOBAL GRANT GROUP_P
365 HANDLER HAVING HOLD HOUR_P
367 ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT
368 INDEX INHERITS INITIALLY INNER_P INOUT INPUT_P
369 INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT
370 INTERVAL INTO INVOKER IS ISNULL ISOLATION
376 LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEFT LEVEL LIKE LIMIT LISTEN
377 LOAD LOCAL LOCATION LOCK_P
379 MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
381 NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
382 NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P
385 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR ORDER
386 OUT_P OUTER_P OVERLAPS OVERLAY OWNER
388 PARTIAL PASSWORD PLACING POSITION
389 PRECISION PRESERVE PREPARE PRIMARY PRIOR PRIVILEGES PROCEDURAL PROCEDURE
393 READ REAL RECHECK REFERENCES REINDEX RELATIVE_P RENAME REPEATABLE REPLACE
394 RESET RESTART RESTRICT RETURNS REVOKE RIGHT ROLLBACK ROW ROWS RULE
396 SCHEMA SCROLL SECOND_P SECURITY SELECT SEQUENCE SERIALIZABLE
397 SESSION SESSION_USER SET SETOF SHARE SHOW SIMILAR SIMPLE SMALLINT SOME
398 STABLE START STATEMENT STATISTICS STDIN STDOUT STORAGE STRICT_P
401 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP TO TOAST
402 TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P TRUNCATE TRUSTED TYPE_P
403 UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL UPDATE USAGE
406 VACUUM VALID VALUES VARCHAR VARYING VERBOSE VIEW VOLATILE
407 WHEN WHERE WITH WITHOUT WORK WRITE
411 /* The grammar thinks these are keywords, but they are not in the keywords.c
412 * list and so can never be entered directly. The filter in parser.c
413 * creates these tokens when required.
417 /* Special token types, not actually keywords - see the "lex" file */
418 %token <str> IDENT SCONST Op CSTRING CVARIABLE CPP_LINE IP BCONST XCONST
419 %token <ival> ICONST PARAM
422 /* precedence: lowest to highest */
430 %nonassoc LIKE ILIKE SIMILAR
435 %left POSTFIXOP /* dummy for postfix Op rules */
436 %left Op OPERATOR /* multi-character ops and user-defined operators */
439 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN
443 /* Unary Operators */
450 %left JOIN UNIONJOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
452 %type <str> Iconst Fconst Sconst TransactionStmt CreateStmt UserId
453 %type <str> CreateAsElement OptCreateAs CreateAsList CreateAsStmt
454 %type <str> comment_text ConstraintDeferrabilitySpec TableElementList
455 %type <str> key_match ColLabel SpecialRuleRelation ColId columnDef
456 %type <str> ColConstraint ColConstraintElem drop_type Bconst Iresult
457 %type <str> TableConstraint OptTableElementList Xconst opt_transaction
458 %type <str> ConstraintElem key_actions ColQualList type_name
459 %type <str> target_list target_el update_target_list alias_clause
460 %type <str> update_target_el qualified_name database_name alter_using
461 %type <str> access_method attr_name index_name name func_name
462 %type <str> file_name AexprConst c_expr ConstTypename var_list
463 %type <str> a_expr b_expr TruncateStmt CommentStmt OnCommitOption opt_by
464 %type <str> opt_indirection expr_list extract_list extract_arg
465 %type <str> position_list substr_list substr_from alter_column_default
466 %type <str> trim_list in_expr substr_for attrs TableFuncElement
467 %type <str> Typename SimpleTypename Numeric opt_float opt_numeric
468 %type <str> opt_decimal Character character opt_varying opt_charset
469 %type <str> opt_timezone opt_interval table_ref fetch_direction
470 %type <str> ConstDatetime AlterDomainStmt AlterSeqStmt
471 %type <str> SelectStmt into_clause OptTemp ConstraintAttributeSpec
472 %type <str> opt_table opt_all sort_clause sortby_list ConstraintAttr
473 %type <str> sortby qualified_name_list name_list ColId_or_Sconst
474 %type <str> group_clause having_clause from_clause opt_distinct opt_hold
475 %type <str> join_outer where_clause relation_expr sub_type arg_class
476 %type <str> opt_column_list insert_rest InsertStmt WithOidsAs param_name
477 %type <str> columnList DeleteStmt LockStmt UpdateStmt DeclareCursorStmt
478 %type <str> NotifyStmt columnElem UnlistenStmt TableElement rowdefinition
479 %type <str> copy_delimiter ListenStmt CopyStmt copy_file_name opt_binary
480 %type <str> FetchStmt from_in CreateOpClassStmt like_including_defaults
481 %type <str> ClosePortalStmt DropStmt VacuumStmt AnalyzeStmt opt_verbose
482 %type <str> opt_full func_arg OptWithOids opt_freeze alter_table_cmd
483 %type <str> analyze_keyword opt_name_list ExplainStmt index_params
484 %type <str> index_elem opt_class access_method_clause alter_table_cmds
485 %type <str> index_opt_unique IndexStmt func_return ConstInterval
486 %type <str> func_args_list func_args opt_with def_arg overlay_placing
487 %type <str> def_elem def_list definition DefineStmt select_with_parens
488 %type <str> opt_instead event RuleActionList opt_using CreateAssertStmt
489 %type <str> RuleActionStmtOrEmpty RuleActionMulti func_as reindex_type
490 %type <str> RuleStmt opt_column oper_argtypes NumConst var_name
491 %type <str> MathOp RemoveFuncStmt aggr_argtype for_update_clause
492 %type <str> RemoveAggrStmt opt_procedural select_no_parens CreateCastStmt
493 %type <str> RemoveOperStmt RenameStmt all_Op opt_Trusted opt_lancompiler
494 %type <str> VariableSetStmt var_value zone_value VariableShowStmt
495 %type <str> VariableResetStmt AlterTableStmt from_list overlay_list
496 %type <str> user_list OptUserList OptUserElem relation_name OptTableSpace
497 %type <str> CreateUserStmt AlterUserStmt CreateSeqStmt OptSeqList
498 %type <str> OptSeqElem TriggerForSpec TriggerForOpt TriggerForType
499 %type <str> DropTrigStmt TriggerOneEvent TriggerEvents RuleActionStmt
500 %type <str> TriggerActionTime CreateTrigStmt DropPLangStmt DropCastStmt
501 %type <str> CreatePLangStmt TriggerFuncArgs TriggerFuncArg simple_select
502 %type <str> ViewStmt LoadStmt CreatedbStmt createdb_opt_item ExplainableStmt
503 %type <str> createdb_opt_list opt_encoding OptInherit opt_equal
504 %type <str> AlterUserSetStmt privilege_list privilege privilege_target
505 %type <str> opt_grant_grant_option opt_revoke_grant_option cursor_options
506 %type <str> transaction_mode_list_or_empty transaction_mode_list
507 %type <str> function_with_argtypes_list function_with_argtypes IntConstVar
508 %type <str> DropdbStmt ClusterStmt grantee RevokeStmt Bit DropOpClassStmt
509 %type <str> GrantStmt privileges PosAllConst constraints_set_list
510 %type <str> ConstraintsSetStmt AllConst CreateDomainStmt opt_nowait
511 %type <str> case_expr when_clause_list case_default case_arg when_clause
512 %type <str> select_clause opt_select_limit select_limit_value opt_recheck
513 %type <str> ConstraintTimeSpec AlterDatabaseSetStmt DropAssertStmt
514 %type <str> select_offset_value ReindexStmt join_type opt_boolean
515 %type <str> join_qual update_list joined_table opclass_item fetch_count
516 %type <str> opt_lock lock_type OptGroupList OptGroupElem array_expr_list
517 %type <str> OptConstrFromTable OptTempTableName StringConst array_expr
518 %type <str> constraints_set_mode comment_type opt_empty_parentheses
519 %type <str> CreateGroupStmt AlterGroupStmt DropGroupStmt key_delete
520 %type <str> opt_force key_update CreateSchemaStmt PosIntStringConst
521 %type <str> IntConst PosIntConst grantee_list func_type opt_or_replace
522 %type <str> select_limit opt_for_update_clause CheckPointStmt
523 %type <str> OptSchemaName OptSchemaEltList schema_stmt opt_drop_behavior
524 %type <str> handler_name any_name_list any_name opt_as insert_column_list
525 %type <str> columnref function_name insert_target_el AllConstVar
526 %type <str> insert_target_list insert_column_item DropRuleStmt
527 %type <str> createfunc_opt_item set_rest var_list_or_default
528 %type <str> CreateFunctionStmt createfunc_opt_list func_table
529 %type <str> DropUserStmt copy_from copy_opt_list copy_opt_item
530 %type <str> opt_oids TableLikeClause key_action opt_definition
531 %type <str> cast_context row qual_Op qual_all_Op opt_default
532 %type <str> CreateConversionStmt any_operator opclass_item_list
533 %type <str> iso_level type_list CharacterWithLength ConstCharacter
534 %type <str> CharacterWithoutLength BitWithLength BitWithoutLength
535 %type <str> ConstBit GenericType TableFuncElementList opt_analyze
536 %type <str> opt_sort_clause transaction_access_mode subquery_Op
537 %type <str> ECPGWhenever ECPGConnect connection_target ECPGOpen
538 %type <str> indicator ECPGExecute ECPGPrepare ecpg_using ecpg_into
539 %type <str> storage_declaration storage_clause opt_initializer c_anything
540 %type <str> variable_list variable c_thing c_term ECPGKeywords_vanames
541 %type <str> opt_pointer ECPGDisconnect dis_name storage_modifier
542 %type <str> ECPGRelease execstring server_name ECPGVarDeclaration
543 %type <str> connection_object opt_server opt_port c_stuff c_stuff_item
544 %type <str> user_name opt_user char_variable ora_user ident opt_reference
545 %type <str> var_type_declarations quoted_ident_stringvar ECPGKeywords_rest
546 %type <str> db_prefix server opt_options opt_connection_name c_list
547 %type <str> ECPGSetConnection ECPGTypedef c_args ECPGKeywords ECPGCKeywords
548 %type <str> enum_type civar civarind ECPGCursorStmt ECPGDeallocate
549 %type <str> ECPGFree ECPGDeclare ECPGVar opt_at enum_definition
550 %type <str> struct_union_type s_struct_union vt_declarations execute_rest
551 %type <str> var_declaration type_declaration single_vt_declaration
552 %type <str> ECPGSetAutocommit on_off variable_declarations ECPGDescribe
553 %type <str> ECPGAllocateDescr ECPGDeallocateDescr symbol opt_output
554 %type <str> ECPGGetDescriptorHeader ECPGColLabel single_var_declaration
555 %type <str> reserved_keyword unreserved_keyword ecpg_interval opt_ecpg_using
556 %type <str> col_name_keyword func_name_keyword precision opt_scale
557 %type <str> ECPGTypeName using_list ECPGColLabelCommon UsingConst
558 %type <str> inf_val_list inf_col_list using_descriptor into_descriptor
559 %type <str> prepared_name struct_union_type_with_symbol
560 %type <str> ECPGunreserved ECPGunreserved_interval cvariable
561 %type <str> AlterOwnerStmt OptTableSpaceOwner CreateTableSpaceStmt
562 %type <str> DropTableSpaceStmt indirection indirection_el ECPGSetDescriptorHeader
564 %type <struct_union> s_struct_union_symbol
566 %type <descriptor> ECPGGetDescriptor ECPGSetDescriptor
568 %type <type_enum> simple_type signed_type unsigned_type
570 %type <dtype_enum> descriptor_item desc_header_item
572 %type <type> var_type
574 %type <action> action
576 %type <index> opt_array_bounds
581 statements: /*EMPTY*/
582 | statements statement
585 statement: ecpgstart opt_at stmt ';' { connection = NULL; }
587 | ecpgstart ECPGVarDeclaration
589 fprintf(yyout, "%s", $2);
591 output_line_number();
594 | c_thing { fprintf(yyout, "%s", $1); free($1); }
595 | CPP_LINE { fprintf(yyout, "%s", $1); free($1); }
596 | '{' { braces_open++; fputs("{", yyout); }
597 | '}' { remove_typedefs(braces_open); remove_variables(braces_open--); fputs("}", yyout); }
600 opt_at: AT connection_target
604 * Do we have a variable as connection target?
605 * Remove the variable from the variable
606 * list or else it will be used twice
608 if (argsinsert != NULL)
612 stmt: AlterDatabaseSetStmt { output_statement($1, 0, connection); }
613 | AlterDomainStmt { output_statement($1, 0, connection); }
614 | AlterGroupStmt { output_statement($1, 0, connection); }
615 | AlterOwnerStmt { output_statement($1, 0, connection); }
616 | AlterSeqStmt { output_statement($1, 0, connection); }
617 | AlterTableStmt { output_statement($1, 0, connection); }
618 | AlterUserSetStmt { output_statement($1, 0, connection); }
619 | AlterUserStmt { output_statement($1, 0, connection); }
620 | AnalyzeStmt { output_statement($1, 0, connection); }
621 | CheckPointStmt { output_statement($1, 0, connection); }
626 /* Informix also has a CLOSE DATABASE command that
627 essantially works like a DISCONNECT CURRENT
629 if (pg_strcasecmp($1+strlen("close "), "database") == 0)
632 mmerror(PARSE_ERROR, ET_ERROR, "no at option for close database statement.\n");
634 fprintf(yyout, "{ ECPGdisconnect(__LINE__, \"CURRENT\");");
639 output_statement($1, 0, connection);
642 output_statement($1, 0, connection);
644 | ClusterStmt { output_statement($1, 0, connection); }
645 | CommentStmt { output_statement($1, 0, connection); }
646 | ConstraintsSetStmt { output_statement($1, 0, connection); }
647 | CopyStmt { output_statement($1, 0, connection); }
648 | CreateAsStmt { output_statement($1, 0, connection); }
649 | CreateAssertStmt { output_statement($1, 0, connection); }
650 | CreateCastStmt { output_statement($1, 0, connection); }
651 | CreateConversionStmt { output_statement($1, 0, connection); }
652 | CreateDomainStmt { output_statement($1, 0, connection); }
653 | CreateFunctionStmt { output_statement($1, 0, connection); }
654 | CreateGroupStmt { output_statement($1, 0, connection); }
655 | CreatePLangStmt { output_statement($1, 0, connection); }
656 | CreateOpClassStmt { output_statement($1, 0, connection); }
657 | CreateSchemaStmt { output_statement($1, 0, connection); }
658 | CreateSeqStmt { output_statement($1, 0, connection); }
659 | CreateStmt { output_statement($1, 0, connection); }
660 | CreateTrigStmt { output_statement($1, 0, connection); }
661 | CreateTableSpaceStmt { output_statement($1, 0, connection); }
662 | CreateUserStmt { output_statement($1, 0, connection); }
663 | CreatedbStmt { output_statement($1, 0, connection); }
664 /*| DeallocateStmt { output_statement($1, 0, connection); }*/
665 | DeclareCursorStmt { output_simple_statement($1); }
666 | DefineStmt { output_statement($1, 0, connection); }
667 | DeleteStmt { output_statement($1, 1, connection); }
668 | DropAssertStmt { output_statement($1, 0, connection); }
669 | DropCastStmt { output_statement($1, 0, connection); }
670 | DropGroupStmt { output_statement($1, 0, connection); }
671 | DropOpClassStmt { output_statement($1, 0, connection); }
672 | DropPLangStmt { output_statement($1, 0, connection); }
673 | DropRuleStmt { output_statement($1, 0, connection); }
674 | DropStmt { output_statement($1, 0, connection); }
675 | DropTableSpaceStmt { output_statement($1, 0, connection); }
676 | DropTrigStmt { output_statement($1, 0, connection); }
677 | DropUserStmt { output_statement($1, 0, connection); }
678 | DropdbStmt { output_statement($1, 0, connection); }
679 | ExplainStmt { output_statement($1, 0, connection); }
680 /* | ExecuteStmt { output_statement($1, 0, connection); }*/
681 | FetchStmt { output_statement($1, 1, connection); }
682 | GrantStmt { output_statement($1, 0, connection); }
683 | IndexStmt { output_statement($1, 0, connection); }
684 | InsertStmt { output_statement($1, 1, connection); }
685 | ListenStmt { output_statement($1, 0, connection); }
686 | LoadStmt { output_statement($1, 0, connection); }
687 | LockStmt { output_statement($1, 0, connection); }
688 | NotifyStmt { output_statement($1, 0, connection); }
689 /* | PrepareStmt { output_statement($1, 0, connection); }*/
690 | ReindexStmt { output_statement($1, 0, connection); }
691 | RemoveAggrStmt { output_statement($1, 0, connection); }
692 | RemoveOperStmt { output_statement($1, 0, connection); }
693 | RemoveFuncStmt { output_statement($1, 0, connection); }
694 | RenameStmt { output_statement($1, 0, connection); }
695 | RevokeStmt { output_statement($1, 0, connection); }
696 | RuleStmt { output_statement($1, 0, connection); }
697 | SelectStmt { output_statement($1, 1, connection); }
700 fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", $1);
704 | TruncateStmt { output_statement($1, 0, connection); }
705 | UnlistenStmt { output_statement($1, 0, connection); }
706 | UpdateStmt { output_statement($1, 1, connection); }
707 | VacuumStmt { output_statement($1, 0, connection); }
708 | VariableSetStmt { output_statement($1, 0, connection); }
709 | VariableShowStmt { output_statement($1, 0, connection); }
710 | VariableResetStmt { output_statement($1, 0, connection); }
711 | ViewStmt { output_statement($1, 0, connection); }
714 fprintf(yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
721 mmerror(PARSE_ERROR, ET_ERROR, "no at option for connect statement.\n");
723 fprintf(yyout, "{ ECPGconnect(__LINE__, %d, %s, %d); ", compat, $1, autocommit);
730 output_simple_statement($1);
735 mmerror(PARSE_ERROR, ET_ERROR, "no at option for deallocate statement.\n");
736 fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s);", compat, $1);
740 | ECPGDeallocateDescr
743 mmerror(PARSE_ERROR, ET_ERROR, "no at option for deallocate statement.\n");
744 fprintf(yyout,"ECPGdeallocate_desc(__LINE__, %s);",$1);
750 output_simple_statement($1);
754 fprintf(yyout, "{ ECPGdescribe(__LINE__, %s,", $1);
755 dump_variables(argsresult, 1);
756 fputs("ECPGt_EORT);", yyout);
758 output_line_number();
760 /* whenever_action(2); */
766 mmerror(PARSE_ERROR, ET_ERROR, "no at option for disconnect statement.\n");
768 fprintf(yyout, "{ ECPGdisconnect(__LINE__, %s);",
769 $1 ? $1 : "\"CURRENT\"");
775 output_statement($1, 0, connection);
779 fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, \"%s\");", compat, $1);
786 lookup_descriptor($1.name, connection);
787 output_get_descr($1.name, $1.str);
791 | ECPGGetDescriptorHeader
793 lookup_descriptor($1, connection);
794 output_get_descr_header($1);
801 if ((ptr = add_additional_variables($1, true)) != NULL)
802 output_statement(mm_strdup(ptr->command), 0, ptr->connection ? mm_strdup(ptr->connection) : NULL);
808 mmerror(PARSE_ERROR, ET_ERROR, "no at option for prepare statement.\n");
810 fprintf(yyout, "{ ECPGprepare(__LINE__, %s);", $1);
814 | ECPGRelease { /* output already done */ }
817 fprintf(yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
824 mmerror(PARSE_ERROR, ET_ERROR, "no at option for set connection statement.\n");
826 fprintf(yyout, "{ ECPGsetconn(__LINE__, %s);", $1);
832 lookup_descriptor($1.name, connection);
833 output_set_descr($1.name, $1.str);
837 | ECPGSetDescriptorHeader
839 lookup_descriptor($1, connection);
840 output_set_descr_header($1);
846 mmerror(PARSE_ERROR, ET_ERROR, "no at option for typedef statement.\n");
848 fprintf(yyout, "%s", $1);
850 output_line_number();
855 mmerror(PARSE_ERROR, ET_ERROR, "no at option for var statement.\n");
857 output_simple_statement($1);
862 mmerror(PARSE_ERROR, ET_ERROR, "no at option for whenever statement.\n");
864 output_simple_statement($1);
870 * We start with a lot of stuff that's very similar to the backend's parsing
873 /*****************************************************************************
875 * Create a new Postgres DBMS user
878 *****************************************************************************/
880 CreateUserStmt: CREATE USER UserId opt_with OptUserList
881 { $$ = cat_str(4, make_str("create user"), $3, make_str("with"), $5); }
884 opt_with: WITH { $$ = make_str("with"); }
885 | /*EMPTY*/ { $$ = EMPTY; }
889 /*****************************************************************************
891 * Alter a postgresql DBMS user
894 *****************************************************************************/
896 AlterUserStmt: ALTER USER UserId OptUserList
897 { $$ = cat_str(3, make_str("alter user"), $3, $4); }
898 | ALTER USER UserId WITH OptUserList
899 { $$ = cat_str(4, make_str("alter user"), $3, make_str("with"), $5); }
902 AlterUserSetStmt: ALTER USER UserId SET set_rest
903 { $$ = cat_str(4, make_str("alter user"), $3, make_str("set"), $5); }
904 | ALTER USER UserId VariableResetStmt
905 { $$ = cat_str(3, make_str("alter user"), $3, $4); }
908 /*****************************************************************************
910 * Drop a postgresql DBMS user
913 *****************************************************************************/
914 DropUserStmt: DROP USER user_list
915 { $$ = cat2_str(make_str("drop user"), $3);}
918 * Options for CREATE USER and ALTER USER
921 OptUserList: OptUserList OptUserElem { $$ = cat2_str($1, $2); }
922 | /* EMPTY */ { $$ = EMPTY; }
925 OptUserElem: PASSWORD Sconst
926 { $$ = cat2_str(make_str("password"), $2); }
928 { $$ = cat2_str(make_str("sysid"), $2); }
930 { $$ = make_str("createdb"); }
932 { $$ = make_str("nocreatedb"); }
934 { $$ = make_str("createuser"); }
936 { $$ = make_str("nocreateuser"); }
937 | IN_P GROUP_P user_list
938 { $$ = cat2_str(make_str("in group"), $3); }
940 { $$ = cat2_str(make_str("valid until"), $3); }
943 user_list: user_list ',' UserId
944 { $$ = cat_str(3, $1, make_str(","), $3); }
949 /*****************************************************************************
951 * Create a postgresql group
954 ****************************************************************************/
955 CreateGroupStmt: CREATE GROUP_P UserId OptGroupList
956 { $$ = cat_str(3, make_str("create group"), $3, $4); }
957 | CREATE GROUP_P UserId WITH OptGroupList
958 { $$ = cat_str(4, make_str("create group"), $3, make_str("with"), $5); }
962 * Options for CREATE GROUP
964 OptGroupList: OptGroupList OptGroupElem { $$ = cat2_str($1, $2); }
965 | /* EMPTY */ { $$ = EMPTY; }
968 OptGroupElem: USER user_list
969 { $$ = cat2_str(make_str("user"), $2); }
971 { $$ = cat2_str(make_str("sysid"), $2); }
975 /*****************************************************************************
977 * Alter a postgresql group
980 *****************************************************************************/
981 AlterGroupStmt: ALTER GROUP_P UserId ADD USER user_list
982 { $$ = cat_str(4, make_str("alter group"), $3, make_str("add user"), $6); }
983 | ALTER GROUP_P UserId DROP USER user_list
984 { $$ = cat_str(4, make_str("alter group"), $3, make_str("drop user"), $6); }
987 /*****************************************************************************
989 * Drop a postgresql group
992 *****************************************************************************/
993 DropGroupStmt: DROP GROUP_P UserId
994 { $$ = cat2_str(make_str("drop group"), $3); }
997 /*****************************************************************************
999 * Manipulate a schema
1002 *****************************************************************************/
1004 CreateSchemaStmt: CREATE SCHEMA OptSchemaName AUTHORIZATION UserId OptTableSpace OptSchemaEltList
1005 { $$ = cat_str(6, make_str("create schema"), $3, make_str("authorization"), $5, $6, $7); }
1006 | CREATE SCHEMA ColId OptTableSpace OptSchemaEltList
1007 { $$ = cat_str(4, make_str("create schema"), $3, $4, $5); }
1010 OptSchemaName: ColId { $$ = $1; }
1011 | /* EMPTY */ { $$ = EMPTY; }
1014 OptSchemaEltList: OptSchemaEltList schema_stmt { $$ = cat2_str($1, $2); }
1015 | /* EMPTY */ { $$ = EMPTY; }
1019 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1020 * statement (in addition to by themselves).
1022 schema_stmt: CreateStmt { $$ = $1; }
1023 | IndexStmt { $$ = $1; }
1024 | CreateSeqStmt { $$ = $1; }
1025 | CreateTrigStmt { $$ = $1; }
1026 | GrantStmt { $$ = $1; }
1027 | ViewStmt { $$ = $1; }
1032 /*****************************************************************************
1034 * Set PG internal variable
1035 * SET name TO 'var_value'
1036 * Include SQL92 syntax (thomas 1997-10-22):
1037 * SET TIME ZONE 'var_value'
1039 *****************************************************************************/
1040 VariableSetStmt: SET set_rest
1041 { $$ = cat2_str(make_str("set"), $2 ); }
1042 | SET LOCAL set_rest
1043 { $$ = cat2_str(make_str("set local"), $3 ); }
1044 | SET SESSION set_rest
1045 { $$ = cat2_str(make_str("set session"), $3 ); }
1048 set_rest: var_name TO var_list_or_default
1049 { $$ = cat_str(3, $1, make_str("to"), $3); }
1050 | var_name "=" var_list_or_default
1051 { $$ = cat_str(3, $1, make_str("="), $3); }
1052 | TIME ZONE zone_value
1053 { $$ = cat2_str(make_str("time zone"), $3); }
1054 | TRANSACTION transaction_mode_list
1055 { $$ = cat2_str(make_str("transaction"), $2); }
1056 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1057 { $$ = cat2_str(make_str("session characteristics as transaction"), $5); }
1058 | NAMES opt_encoding
1059 { $$ = cat2_str(make_str("names"), $2); }
1060 | SESSION AUTHORIZATION ColId_or_Sconst
1061 { $$ = cat2_str(make_str("session authorization"), $3); }
1062 | SESSION AUTHORIZATION DEFAULT
1063 { $$ = make_str("session authorization default"); }
1066 var_name: ColId { $$ = $1; }
1067 | var_name '.' ColId { $$ = cat_str(3, $1, make_str("."), $3); }
1071 var_list_or_default: var_list
1074 { $$ = make_str("default"); }
1079 | var_list ',' var_value
1080 { $$ = cat_str(3, $1, make_str(","), $3); }
1083 iso_level: READ UNCOMMITTED { $$ = make_str("read uncommitted"); }
1084 | READ COMMITTED { $$ = make_str("read committed"); }
1085 | REPEATABLE READ { $$ = make_str("repeatable read"); }
1086 | SERIALIZABLE { $$ = make_str("serializable"); }
1089 var_value: opt_boolean { $$ = $1; }
1090 | AllConst { $$ = $1; }
1091 | ColId { $$ = $1; }
1094 opt_boolean: TRUE_P { $$ = make_str("true"); }
1095 | FALSE_P { $$ = make_str("false"); }
1096 | ON { $$ = make_str("on"); }
1097 | OFF { $$ = make_str("off"); }
1099 /* Timezone values can be:
1100 * - a string such as 'pst8pdt'
1101 * - a column identifier such as "pst8pdt"
1102 * - an integer or floating point number
1103 * - a time interval per SQL99
1104 * ConstInterval and ColId give shift/reduce errors,
1105 * so use IDENT and reject anything which is a reserved word.
1107 zone_value: AllConst { $$ = $1; }
1108 | ident { $$ = $1; }
1109 | ConstInterval StringConst opt_interval
1110 { $$ = cat_str(3, $1, $2, $3); }
1111 | ConstInterval '(' PosIntConst ')' StringConst opt_interval
1112 { $$ = cat_str(6, $1, make_str("("), $3, make_str(")"), $5, $6); }
1114 { $$ = make_str("default"); }
1116 { $$ = make_str("local"); }
1119 opt_encoding: StringConst { $$ = $1; }
1120 | DEFAULT { $$ = make_str("default"); }
1121 | /*EMPTY*/ { $$ = EMPTY; }
1124 ColId_or_Sconst: ColId { $$ = $1; }
1125 | StringConst { $$ = $1; }
1128 VariableShowStmt: SHOW ColId
1129 { $$ = cat2_str(make_str("show"), $2); }
1131 { $$ = make_str("show time zone"); }
1132 | SHOW TRANSACTION ISOLATION LEVEL
1133 { $$ = make_str("show transaction isolation level"); }
1134 | SHOW SESSION AUTHORIZATION
1135 { $$ = make_str("show session authorization"); }
1137 { $$ = make_str("show all"); }
1140 VariableResetStmt: RESET ColId
1141 { $$ = cat2_str(make_str("reset"), $2); }
1143 { $$ = make_str("reset time zone"); }
1144 | RESET TRANSACTION ISOLATION LEVEL
1145 { $$ = make_str("reset transaction isolation level"); }
1146 | RESET SESSION AUTHORIZATION
1147 { $$ = make_str("reset session authorization"); }
1149 { $$ = make_str("reset all"); }
1152 ConstraintsSetStmt: SET CONSTRAINTS constraints_set_list constraints_set_mode
1153 { $$ = cat_str(3, make_str("set constraints"), $3, $4); }
1156 constraints_set_list: ALL
1157 { $$ = make_str("all"); }
1162 constraints_set_mode: DEFERRED { $$ = make_str("deferred"); }
1163 | IMMEDIATE { $$ = make_str("immediate"); }
1167 * Checkpoint statement
1169 CheckPointStmt: CHECKPOINT { $$= make_str("checkpoint"); }
1173 /*****************************************************************************
1175 * ALTER TABLE variations
1177 *****************************************************************************/
1180 ALTER TABLE relation_expr alter_table_cmds
1181 { $$ = cat_str(3, make_str("alter table"), $3, $4); }
1185 alter_table_cmd { $$ = $1; }
1186 | alter_table_cmds ',' alter_table_cmd { $$ = cat_str(3, $1, make_str(","), $3); }
1190 ADD opt_column columnDef
1191 /* ALTER TABLE <relation> ADD [COLUMN] <coldef> */
1192 { $$ = cat_str(3, make_str("add"), $2, $3); }
1193 /* ALTER TABLE <relation> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1194 | ALTER opt_column ColId alter_column_default
1195 { $$ = cat_str(4, make_str("alter"), $2, $3, $4); }
1196 /* ALTER TABLE <relation> ALTER [COLUMN] <colname> DROP NOT NULL */
1197 | ALTER opt_column ColId DROP NOT NULL_P
1198 { $$ = cat_str(4, make_str("alter"), $2, $3, make_str("drop not null")); }
1199 /* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET NOT NULL */
1200 | ALTER opt_column ColId SET NOT NULL_P
1201 { $$ = cat_str(4, make_str("alter"), $2, $3, make_str("set not null")); }
1202 /* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET STATISTICS <IntegerOnly> */
1203 | ALTER opt_column ColId SET STATISTICS PosIntConst
1204 { $$ = cat_str(5, make_str("alter"), $2, $3, make_str("set statistics"), $6); }
1205 /* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1206 | ALTER opt_column ColId SET STORAGE ColId
1207 { $$ = cat_str(5, make_str("alter"), $2, $3, make_str("set storage"), $6); }
1208 /* ALTER TABLE <relation> DROP [COLUMN] <colname> {RESTRICT|CASCADE} */
1209 | DROP opt_column ColId opt_drop_behavior
1210 { $$ = cat_str(4, make_str("drop"), $2, $3, $4); }
1211 /* ALTER TABLE <relation> ALTER [COLUMN] <colname> TYPE <typename> [ USING <expression> ] */
1212 | ALTER opt_column ColId TYPE_P Typename alter_using
1213 { $$ = cat_str(6, make_str("alter"), $2, $3, make_str("type"), $5, $6); }
1214 /* ALTER TABLE <relation> ADD CONSTRAINT ... */
1215 | ADD TableConstraint
1216 { $$ = cat_str(2, make_str("add"), $2); }
1217 /* ALTER TABLE <relation> DROP CONSTRAINT ... */
1218 | DROP CONSTRAINT name opt_drop_behavior
1219 { $$ = cat_str(3, make_str("drop constraint"), $3, $4); }
1220 /* ALTER TABLE <relation> SET WITHOUT OIDS */
1222 { $$ = make_str("set without oids"); }
1223 /* ALTER TABLE <name> CREATE TOAST TABLE */
1224 | CREATE TOAST TABLE
1225 { $$ = make_str("create toast table"); }
1226 /* ALTER TABLE <name> OWNER TO UserId */
1228 { $$ = cat_str(2, make_str("owner to"), $3); }
1229 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1231 { $$ = cat_str(2, make_str("cluster on"), $3); }
1232 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1233 | SET WITHOUT CLUSTER
1234 { $$ = make_str("set without cluster"); }
1235 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1236 | SET TABLESPACE name
1237 { $$ = cat_str(2, make_str("set tablespace"), $3); }
1240 alter_column_default:
1241 SET DEFAULT a_expr { $$ = cat2_str(make_str("set default"), $3); }
1242 | DROP DEFAULT { $$ = make_str("drop default"); }
1245 opt_drop_behavior: CASCADE { $$ = make_str("cascade"); }
1246 | RESTRICT { $$ = make_str("restrict"); }
1247 | /* EMPTY */ { $$ = EMPTY; }
1250 alter_using: USING a_expr { $$ = cat2_str(make_str("using"), $2); }
1251 | /* EMPTY */ { $$ = EMPTY; }
1254 /*****************************************************************************
1257 * close <portalname>
1259 *****************************************************************************/
1261 ClosePortalStmt: CLOSE name
1263 $$ = cat2_str(make_str("close"), $2);
1267 /*****************************************************************************
1270 * COPY [BINARY] <relname> FROM/TO
1271 * [USING DELIMITERS <delimiter>]
1273 *****************************************************************************/
1275 CopyStmt: COPY opt_binary qualified_name opt_oids copy_from
1276 copy_file_name copy_delimiter opt_with copy_opt_list
1277 { $$ = cat_str(9, make_str("copy"), $2, $3, $4, $5, $6, $7, $8, $9); }
1280 copy_from: TO { $$ = make_str("to"); }
1281 | FROM { $$ = make_str("from"); }
1285 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1286 * used depends on the direction. (It really doesn't make sense to copy from
1287 * stdout. We silently correct the "typo". - AY 9/94
1289 copy_file_name: StringConst { $$ = $1; }
1290 | STDIN { $$ = make_str("stdin"); }
1291 | STDOUT { $$ = make_str("stdout"); }
1294 copy_opt_list: copy_opt_list copy_opt_item { $$ = cat2_str($1, $2); }
1295 | /* EMPTY */ { $$ = EMPTY; }
1298 copy_opt_item: BINARY { $$ = make_str("binary"); }
1299 | OIDS { $$ = make_str("oids"); }
1300 | DELIMITER opt_as StringConst
1301 { $$ = cat_str(3, make_str("delimiter"), $2, $3); }
1302 | NULL_P opt_as StringConst
1303 { $$ = cat_str(3, make_str("null"), $2, $3); }
1304 | CSV { $$ = make_str("csv"); }
1305 | QUOTE opt_as Sconst
1306 { $$ = cat_str(3, make_str("quote"), $2, $3); }
1307 | ESCAPE opt_as Sconst
1308 { $$ = cat_str(3, make_str("escape"), $2, $3); }
1309 | FORCE QUOTE columnList
1310 { $$ = cat2_str(make_str("force quote"), $3); }
1311 | FORCE NOT NULL_P columnList
1312 { $$ = cat2_str(make_str("force not null"), $4); }
1316 opt_binary: BINARY { $$ = make_str("binary"); }
1317 | /* EMPTY */ { $$ = EMPTY; }
1320 opt_oids: WITH OIDS { $$ = make_str("with oids"); }
1321 | /* EMPTY */ { $$ = EMPTY; }
1326 * the default copy delimiter is tab but the user can configure it
1328 copy_delimiter: opt_using DELIMITERS StringConst
1329 { $$ = cat_str(3, $1, make_str("delimiters"), $3); }
1334 opt_using: USING { $$ = make_str("using"); }
1335 | /* EMPTY */ { $$ = EMPTY; }
1338 /*****************************************************************************
1341 * CREATE TABLE relname
1343 *****************************************************************************/
1345 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
1346 OptInherit OptWithOids OnCommitOption OptTableSpace
1347 { $$ = cat_str(11, make_str("create"), $2, make_str("table"), $4, make_str("("), $6, make_str(")"), $8, $9, $10, $11); }
1348 | CREATE OptTemp TABLE qualified_name OF qualified_name
1349 '(' OptTableElementList ')' OptWithOids OnCommitOption OptTableSpace
1350 { $$ = cat_str(12, make_str("create"), $2, make_str("table"), $4, make_str("of"), $6, make_str("("), $8, make_str(")"), $10, $11, $12); }
1354 * Redundancy here is needed to avoid shift/reduce conflicts,
1355 * since TEMP is not a reserved word. See also OptTempTableName.
1358 OptTemp: TEMPORARY { $$ = make_str("temporary"); }
1359 | TEMP { $$ = make_str("temp"); }
1360 | LOCAL TEMPORARY { $$ = make_str("local temporary"); }
1361 | LOCAL TEMP { $$ = make_str("local temp"); }
1362 | GLOBAL TEMPORARY { $$ = make_str("global temporary"); }
1363 | GLOBAL TEMP { $$ = make_str("global temp"); }
1364 | /*EMPTY*/ { $$ = EMPTY; }
1368 OptTableElementList: TableElementList
1373 TableElementList: TableElement
1375 | TableElementList ',' TableElement
1376 { $$ = cat_str(3, $1, make_str(","), $3); }
1379 TableElement: columnDef { $$ = $1; }
1380 | TableLikeClause { $$ = $1; }
1381 | TableConstraint { $$ = $1; }
1384 columnDef: ColId Typename ColQualList
1386 $$ = cat_str(3, $1, $2, $3);
1390 ColQualList: ColQualList ColConstraint { $$ = cat2_str($1,$2); }
1391 | /*EMPTY*/ { $$ = EMPTY; }
1394 ColConstraint: CONSTRAINT name ColConstraintElem
1395 { $$ = cat_str(3, make_str("constraint"), $2, $3); }
1396 | ColConstraintElem { $$ = $1; }
1397 | ConstraintAttr { $$ = $1; }
1400 /* DEFAULT NULL is already the default for Postgres.
1401 * But define it here and carry it forward into the system
1402 * to make it explicit.
1403 * - thomas 1998-09-13
1405 * WITH NULL and NULL are not SQL92-standard syntax elements,
1406 * so leave them out. Use DEFAULT NULL to explicitly indicate
1407 * that a column may have that value. WITH NULL leads to
1408 * shift/reduce conflicts with WITH TIME ZONE anyway.
1409 * - thomas 1999-01-08
1411 ColConstraintElem: NOT NULL_P
1412 { $$ = make_str("not null"); }
1414 { $$ = make_str("null"); }
1416 { $$ = make_str("unique"); }
1418 { $$ = make_str("primary key"); }
1419 | CHECK '(' a_expr ')'
1420 { $$ = cat_str(3, make_str("check ("), $3, make_str(")")); }
1422 { $$ = cat2_str(make_str("default"), $2); }
1423 | REFERENCES qualified_name opt_column_list key_match key_actions
1424 { $$ = cat_str(5, make_str("references"), $2, $3, $4, $5); }
1428 * ConstraintAttr represents constraint attributes, which we parse as if
1429 * they were independent constraint clauses, in order to avoid shift/reduce
1430 * conflicts (since NOT might start either an independent NOT NULL clause
1431 * or an attribute). analyze.c is responsible for attaching the attribute
1432 * information to the preceding "real" constraint node, and for complaining
1433 * if attribute clauses appear in the wrong place or wrong combinations.
1435 * See also ConstraintAttributeSpec, which can be used in places where
1436 * there is no parsing conflict.
1438 ConstraintAttr: DEFERRABLE { $$ = make_str("deferrable"); }
1439 | NOT DEFERRABLE { $$ = make_str("not deferrable"); }
1440 | INITIALLY DEFERRED { $$ = make_str("initially deferred"); }
1441 | INITIALLY IMMEDIATE { $$ = make_str("initially immediate"); }
1444 TableLikeClause: LIKE qualified_name like_including_defaults
1446 $$ = cat_str(3, make_str("like"), $2, $3);
1450 like_including_defaults:
1451 INCLUDING DEFAULTS { $$ = make_str("including defaults"); }
1452 | EXCLUDING DEFAULTS { $$ = make_str("excluding defaults"); }
1453 | /* EMPTY */ { $$ = EMPTY; }
1456 /* ConstraintElem specifies constraint syntax which is not embedded into
1457 * a column definition. ColConstraintElem specifies the embedded form.
1458 * - thomas 1997-12-03
1460 TableConstraint: CONSTRAINT name ConstraintElem
1461 { $$ = cat_str(3, make_str("constraint"), $2, $3); }
1466 ConstraintElem: CHECK '(' a_expr ')'
1467 { $$ = cat_str(3, make_str("check("), $3, make_str(")")); }
1468 | UNIQUE '(' columnList ')'
1469 { $$ = cat_str(3, make_str("unique("), $3, make_str(")")); }
1470 | PRIMARY KEY '(' columnList ')'
1471 { $$ = cat_str(3, make_str("primary key("), $4, make_str(")")); }
1472 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name opt_column_list
1473 key_match key_actions ConstraintAttributeSpec
1474 { $$ = cat_str(8, make_str("foreign key("), $4, make_str(") references"), $7, $8, $9, $10, $11); }
1477 opt_column_list: '(' columnList ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
1478 | /*EMPTY*/ { $$ = EMPTY; }
1481 columnList: columnList ',' columnElem
1482 { $$ = cat_str(3, $1, make_str(","), $3); }
1487 columnElem: ColId { $$ = $1; }
1490 key_match: MATCH FULL
1491 { $$ = make_str("match full"); }
1494 mmerror(PARSE_ERROR, ET_WARNING, "Currently unsupported FOREIGN KEY/MATCH PARTIAL will be passed to backend");
1495 $$ = make_str("match partial");
1501 key_actions: key_delete { $$ = $1; }
1502 | key_update { $$ = $1; }
1503 | key_delete key_update { $$ = cat2_str($1, $2); }
1504 | key_update key_delete { $$ = cat2_str($1, $2); }
1505 | /*EMPTY*/ { $$ = EMPTY; }
1508 key_delete: ON DELETE_P key_action
1509 { $$ = cat2_str(make_str("on delete"), $3); }
1512 key_update: ON UPDATE key_action
1513 { $$ = cat2_str(make_str("on update"), $3); }
1516 key_action: NO ACTION { $$ = make_str("no action"); }
1517 | RESTRICT { $$ = make_str("restrict"); }
1518 | CASCADE { $$ = make_str("cascade"); }
1519 | SET DEFAULT { $$ = make_str("set default"); }
1520 | SET NULL_P { $$ = make_str("set null"); }
1523 OptInherit: INHERITS '(' qualified_name_list ')'
1524 { $$ = cat_str(3, make_str("inherits ("), $3, make_str(")")); }
1529 OptWithOids: WITH OIDS { $$ = make_str("with oids"); }
1530 | WITHOUT OIDS { $$ = make_str("without oids"); }
1531 | /*EMPTY*/ { $$ = EMPTY; }
1534 OnCommitOption: ON COMMIT DROP { $$ = make_str("on commit drop"); }
1535 | ON COMMIT DELETE_P ROWS { $$ = make_str("on commit delete rows"); }
1536 | ON COMMIT PRESERVE ROWS { $$ = make_str("on commit preserve rows"); }
1537 | /*EMPTY*/ { $$ = EMPTY; }
1540 OptTableSpace: TABLESPACE name { $$ = cat2_str(make_str("tablespace"), $2); }
1541 | /*EMPTY*/ { $$ = EMPTY; }
1545 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
1549 CreateAsStmt: CREATE OptTemp TABLE qualified_name OptCreateAs WithOidsAs
1554 mmerror(PARSE_ERROR, ET_ERROR, "CREATE TABLE / AS SELECT may not specify INTO");
1556 $$ = cat_str(8, make_str("create"), $2, make_str("table"), $4, $5, $6, $8);
1561 * To avoid a shift/reduce conflict in CreateAsStmt, we need to
1562 * include the 'AS' terminal in the parsing of WITH/WITHOUT
1563 * OIDS. Unfortunately that means this production is effectively a
1564 * duplicate of OptWithOids.
1567 WITH OIDS AS { $$ = make_str("with oids as"); }
1568 | WITHOUT OIDS AS { $$ = make_str("without oids as"); }
1569 | AS { $$ = make_str("as"); }
1573 OptCreateAs: '(' CreateAsList ')'
1574 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
1579 CreateAsList: CreateAsList ',' CreateAsElement
1580 { $$ = cat_str(3, $1, make_str(","), $3); }
1585 CreateAsElement: ColId { $$ = $1; }
1588 /*****************************************************************************
1591 * CREATE SEQUENCE seqname
1592 * ALTER SEQUENCE seqname
1594 *****************************************************************************/
1596 CreateSeqStmt: CREATE OptTemp SEQUENCE qualified_name OptSeqList
1597 { $$ = cat_str(4, make_str("create"), $2, make_str("sequence"), $4, $5); }
1600 AlterSeqStmt: ALTER SEQUENCE qualified_name OptSeqList
1601 { $$ = cat_str(3,make_str("alter sequence"), $3, $4); }
1604 OptSeqList: OptSeqList OptSeqElem { $$ = cat2_str($1, $2); }
1605 | /*EMPTY*/ { $$ = EMPTY; }
1608 OptSeqElem: CACHE NumConst
1609 { $$ = cat2_str(make_str("cache"), $2); }
1611 { $$ = make_str("cycle"); }
1613 { $$ = make_str("no cycle"); }
1614 | INCREMENT opt_by NumConst
1615 { $$ = cat_str(3, make_str("increment"), $2, $3); }
1617 { $$ = cat2_str(make_str("maxvalue"), $2); }
1619 { $$ = cat2_str(make_str("minvalue"), $2); }
1621 { $$ = make_str("no maxvalue"); }
1623 { $$ = make_str("no minvalue"); }
1624 | START opt_with NumConst
1625 { $$ = cat_str(3, make_str("start"), $2, $3); }
1626 | RESTART opt_with NumConst
1627 { $$ = cat_str(3, make_str("restart"), $2, $3); }
1630 opt_by: BY { $$ = make_str("by"); }
1631 | /*EMPTY*/ { $$ = EMPTY; }
1634 /*****************************************************************************
1637 * CREATE PROCEDURAL LANGUAGE ...
1638 * DROP PROCEDURAL LANGUAGE ...
1640 *****************************************************************************/
1642 CreatePLangStmt: CREATE opt_Trusted opt_procedural LANGUAGE ColId_or_Sconst
1643 HANDLER handler_name opt_lancompiler
1644 { $$ = cat_str(8, make_str("create"), $2, $3, make_str("language"), $5, make_str("handler"), $7, $8); }
1647 opt_Trusted: TRUSTED { $$ = make_str("trusted"); }
1648 | /*EMPTY*/ { $$ = EMPTY; }
1651 /* This ought to be just func_name, but that causes reduce/reduce conflicts
1652 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
1653 * Work around by using simple names instead.
1655 handler_name: name { $$ = $1; }
1656 | name attrs { $$ = cat2_str($1, $2); }
1659 opt_lancompiler: LANCOMPILER StringConst
1660 { $$ = cat2_str(make_str("lancompiler"), $2); }
1665 DropPLangStmt: DROP opt_procedural LANGUAGE StringConst opt_drop_behavior
1666 { $$ = cat_str(5, make_str("drop"), $2, make_str("language"), $4, $5); }
1669 opt_procedural: PROCEDURAL { $$ = make_str("prcedural"); }
1670 | /*EMPTY*/ { $$ = EMPTY; }
1673 /*****************************************************************************
1676 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
1678 *****************************************************************************/
1680 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
1681 { $$ = cat_str(5,make_str("create tablespace"), $3, $4, make_str("location"), $6); }
1684 OptTableSpaceOwner: OWNER name { $$ = cat2_str(make_str("owner"), $2); }
1685 | /*EMPTY*/ { $$ = EMPTY; }
1688 /*****************************************************************************
1691 * DROP TABLESPACE <tablespace>
1693 * No need for drop behaviour as we cannot implement dependencies for
1694 * objects in other databases; we can only support RESTRICT.
1696 ****************************************************************************/
1699 DropTableSpaceStmt: DROP TABLESPACE name { $$ = cat2_str(make_str("drop tablespace"), $3); };
1702 /*****************************************************************************
1705 * CREATE TRIGGER ...
1708 *****************************************************************************/
1710 CreateTrigStmt: CREATE TRIGGER name TriggerActionTime TriggerEvents ON
1711 qualified_name TriggerForSpec
1713 name '(' TriggerFuncArgs ')'
1714 { $$ = cat_str(12, make_str("create trigger"), $3, $4, $5, make_str("on"), $7, $8, make_str("execute procedure"), $11, make_str("("), $13, make_str(")")); }
1715 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
1716 qualified_name OptConstrFromTable
1717 ConstraintAttributeSpec
1718 FOR EACH ROW EXECUTE PROCEDURE
1719 func_name '(' TriggerFuncArgs ')'
1720 { $$ = cat_str(13, make_str("create constraint trigger"), $4, make_str("after"), $6, make_str("on"), $8, $9, $10, make_str("for each row execute procedure"), $16, make_str("("), $18, make_str(")")); }
1723 TriggerActionTime: BEFORE { $$ = make_str("before"); }
1724 | AFTER { $$ = make_str("after"); }
1727 TriggerEvents: TriggerOneEvent
1729 | TriggerOneEvent OR TriggerOneEvent
1730 { $$ = cat_str(3, $1, make_str("or"), $3); }
1731 | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
1732 { $$ = cat_str(5, $1, make_str("or"), $3, make_str("or"), $5); }
1735 TriggerOneEvent: INSERT { $$ = make_str("insert"); }
1736 | DELETE_P { $$ = make_str("delete"); }
1737 | UPDATE { $$ = make_str("update"); }
1740 TriggerForSpec: FOR TriggerForOpt TriggerForType
1741 { $$ = cat_str(3, make_str("for"), $2, $3); }
1746 TriggerForOpt: EACH { $$ = make_str("each"); }
1747 | /*EMPTY*/ { $$ = EMPTY; }
1750 TriggerForType: ROW { $$ = make_str("row"); }
1751 | STATEMENT { $$ = make_str("statement"); }
1754 TriggerFuncArgs: TriggerFuncArg
1756 | TriggerFuncArgs ',' TriggerFuncArg
1757 { $$ = cat_str(3, $1, make_str(","), $3); }
1762 TriggerFuncArg: PosAllConst { $$ = $1; }
1763 | ColId { $$ = $1; }
1766 OptConstrFromTable: /* Empty */ { $$ = EMPTY; }
1767 | FROM qualified_name { $$ = cat2_str(make_str("from"), $2); }
1770 ConstraintAttributeSpec: ConstraintDeferrabilitySpec { $$ = $1; }
1771 | ConstraintDeferrabilitySpec ConstraintTimeSpec
1773 if (strcmp($1, "deferrable") != 0 && strcmp($2, "initially deferrable") == 0 )
1774 mmerror(PARSE_ERROR, ET_ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
1776 $$ = cat2_str($1, $2);
1778 | ConstraintTimeSpec { $$ = $1; }
1779 | ConstraintTimeSpec ConstraintDeferrabilitySpec
1781 if (strcmp($2, "deferrable") != 0 && strcmp($1, "initially deferrable") == 0 )
1782 mmerror(PARSE_ERROR, ET_ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
1784 $$ = cat2_str($1, $2);
1788 ConstraintDeferrabilitySpec: NOT DEFERRABLE
1789 { $$ = make_str("not deferrable"); }
1791 { $$ = make_str("deferrable"); }
1794 ConstraintTimeSpec: INITIALLY IMMEDIATE
1795 { $$ = make_str("initially immediate"); }
1796 | INITIALLY DEFERRED
1797 { $$ = make_str("initially deferred"); }
1800 DropTrigStmt: DROP TRIGGER name ON qualified_name opt_drop_behavior
1801 { $$ = cat_str(5, make_str("drop trigger"), $3, make_str("on"), $5, $6); }
1804 /*****************************************************************************
1807 * CREATE ASSERTION ...
1808 * DROP ASSERTION ...
1810 *****************************************************************************/
1811 CreateAssertStmt: CREATE ASSERTION name
1812 CHECK '(' a_expr ')' ConstraintAttributeSpec
1814 mmerror(PARSE_ERROR, ET_ERROR, "CREATE ASSERTION is not yet supported");
1815 $$ = cat_str(6, make_str("create assertion"), $3, make_str("check ("), $6, make_str(")"), $8);
1819 DropAssertStmt: DROP ASSERTION name
1821 mmerror(PARSE_ERROR, ET_ERROR, "DROP ASSERTION is not yet supported");
1822 $$ = cat2_str(make_str("drop assertion"), $3);
1827 /*****************************************************************************
1830 * define (type,operator,aggregate)
1832 *****************************************************************************/
1834 DefineStmt: CREATE AGGREGATE func_name definition
1835 { $$ = cat_str(3, make_str("create aggregate"), $3, $4); }
1836 | CREATE OPERATOR all_Op definition
1837 { $$ = cat_str(3, make_str("create operator"), $3, $4); }
1838 | CREATE TYPE_P any_name definition
1839 { $$ = cat_str(3, make_str("create type"), $3, $4); }
1840 | CREATE TYPE_P any_name AS rowdefinition
1841 { $$ = cat_str(4, make_str("create type"), $3, make_str("as"), $5); }
1844 rowdefinition: '(' TableFuncElementList ')'
1845 { $$ = cat_str(3, make_str("("), $2, make_str(")"));}
1848 definition: '(' def_list ')'
1849 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
1852 def_list: def_elem { $$ = $1; }
1853 | def_list ',' def_elem { $$ = cat_str(3, $1, make_str(","), $3); }
1856 def_elem: ColLabel '=' def_arg { $$ = cat_str(3, $1, make_str("="), $3); }
1857 | ColLabel { $$ = $1; }
1860 /* Note: any simple identifier will be returned as a type name! */
1861 def_arg: func_return { $$ = $1; }
1862 | qual_all_Op { $$ = $1; }
1863 | AllConst { $$ = $1; }
1866 CreateOpClassStmt: CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
1867 USING access_method AS opclass_item_list
1869 $$ = cat_str(9, make_str("create operator class"), $4, $5, make_str("for type"), $8, make_str("using"), $10, make_str("as"), $12);
1873 opclass_item_list: opclass_item { $$ = $1; }
1874 | opclass_item_list ',' opclass_item { $$ = cat_str(3, $1, make_str(","), $3); }
1877 opclass_item: OPERATOR PosIntConst any_operator opt_recheck
1878 { $$ = cat_str(4, make_str("operator"), $2, $3, $4); }
1879 | OPERATOR PosIntConst any_operator '(' oper_argtypes ')' opt_recheck
1880 { $$ = cat_str(7, make_str("operator"), $2, $3, make_str("("), $5, make_str(")"), $7); }
1881 | FUNCTION PosIntConst func_name func_args
1882 { $$ = cat_str(4, make_str("function"), $2, $3, $4); }
1884 { $$ = cat2_str(make_str("storage"), $2); }
1887 opt_default: DEFAULT { $$ = make_str("default"); }
1888 | /*EMPTY*/ { $$ = EMPTY; }
1891 opt_recheck: RECHECK { $$ = make_str("recheck"); }
1892 | /*EMPTY*/ { $$ = EMPTY; }
1895 DropOpClassStmt: DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
1896 { $$ = cat_str(5,make_str("drop operator class"), $4, make_str("using"), $6, $7); }
1899 /*****************************************************************************
1903 * DROP itemtype itemname [, itemname ...]
1905 *****************************************************************************/
1907 DropStmt: DROP drop_type any_name_list opt_drop_behavior
1908 { $$ = cat_str(4, make_str("drop"), $2, $3, $4); }
1911 drop_type: TABLE { $$ = make_str("table"); }
1912 | SEQUENCE { $$ = make_str("sequence"); }
1913 | VIEW { $$ = make_str("view"); }
1914 | INDEX { $$ = make_str("index"); }
1915 | TYPE_P { $$ = make_str("type"); }
1916 | DOMAIN_P { $$ = make_str("domain"); }
1917 | CONVERSION_P { $$ = make_str("conversion"); }
1918 | SCHEMA { $$ = make_str("schema"); }
1921 any_name_list: any_name
1923 | any_name_list ',' any_name
1924 { $$ = cat_str(3, $1, make_str(","), $3); }
1927 any_name: ColId { $$ = $1; }
1928 | ColId attrs { $$ = cat2_str($1, $2); }
1932 * The slightly convoluted way of writing this production avoids reduce/reduce
1933 * errors against indirection_el.
1935 attrs: '.' attr_name { $$ = cat2_str(make_str("."), $2); }
1936 | '.' attr_name attrs { $$ = cat_str(3, make_str("."), $2, $3); }
1939 /*****************************************************************************
1942 * truncate table relname
1944 *****************************************************************************/
1945 TruncateStmt: TRUNCATE opt_table qualified_name
1946 { $$ = cat_str(3, make_str("truncate table"), $2, $3); }
1949 /*****************************************************************************
1954 *****************************************************************************/
1956 /* This is different from the backend as we try to be compatible with many other
1957 * embedded SQL implementations. So we accept their syntax as well and
1958 * translate it to the PGSQL syntax. */
1960 FetchStmt: FETCH fetch_direction from_in name ecpg_into
1962 add_additional_variables($4, false);
1963 $$ = cat_str(4, make_str("fetch"), $2, $3, $4);
1965 | FETCH fetch_direction name ecpg_into
1967 add_additional_variables($3, false);
1968 $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3);
1970 | FETCH from_in name ecpg_into
1972 add_additional_variables($3, false);
1973 $$ = cat_str(3, make_str("fetch"), $2, $3);
1975 | FETCH name ecpg_into
1977 add_additional_variables($2, false);
1978 $$ = cat2_str(make_str("fetch"), $2);
1980 | FETCH fetch_direction from_in name
1982 add_additional_variables($4, false);
1983 $$ = cat_str(4, make_str("fetch"), $2, $3, $4);
1985 | FETCH fetch_direction name
1987 add_additional_variables($3, false);
1988 $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3);
1990 | FETCH from_in name
1992 add_additional_variables($3, false);
1993 $$ = cat_str(3, make_str("fetch"), $2, $3);
1997 add_additional_variables($2, false);
1998 $$ = cat2_str(make_str("fetch"), $2);
2000 | MOVE fetch_direction from_in name
2001 { $$ = cat_str(4, make_str("move"), $2, $3, $4); }
2003 { $$ = cat2_str(make_str("move"), $2); }
2006 fetch_direction: NEXT { $$ = make_str("next"); }
2007 | PRIOR { $$ = make_str("prior"); }
2008 | FIRST_P { $$ = make_str("first"); }
2009 | LAST_P { $$ = make_str("last"); }
2010 | ABSOLUTE_P fetch_count { $$ = cat2_str(make_str("absolute"), $2); }
2011 | RELATIVE_P fetch_count { $$ = cat2_str(make_str("relative"), $2); }
2012 | fetch_count { $$ = $1; }
2013 | ALL { $$ = make_str("all"); }
2014 | FORWARD { $$ = make_str("forward"); }
2015 | FORWARD fetch_count { $$ = cat2_str(make_str("forward"), $2); }
2016 | FORWARD ALL { $$ = make_str("forward all"); }
2017 | BACKWARD { $$ = make_str("backward"); }
2018 | BACKWARD fetch_count { $$ = cat2_str(make_str("backward"), $2); }
2019 | BACKWARD ALL { $$ = make_str("backward all"); }
2022 fetch_count: IntConst { $$ = $1; }
2025 from_in: IN_P { $$ = make_str("in"); }
2026 | FROM { $$ = make_str("from"); }
2029 CommentStmt: COMMENT ON comment_type name IS comment_text
2030 { $$ = cat_str(5, make_str("comment on"), $3, $4, make_str("is"), $6); }
2031 | COMMENT ON AGGREGATE func_name '(' aggr_argtype ')' IS comment_text
2032 { $$ = cat_str(6, make_str("comment on aggregate"), $4, make_str("("), $6, make_str(") is"), $9); }
2033 | COMMENT ON FUNCTION func_name func_args IS comment_text
2034 { $$ = cat_str(5, make_str("comment on function"), $4, $5, make_str("is"), $7); }
2035 | COMMENT ON OPERATOR all_Op '(' oper_argtypes ')' IS comment_text
2036 { $$ = cat_str(6, make_str("comment on operator"), $4, make_str("("), $6, make_str(") is"), $9); }
2037 | COMMENT ON TRIGGER name ON any_name IS comment_text
2038 { $$ = cat_str(6, make_str("comment on trigger"), $4, make_str("on"), $6, make_str("is"), $8); }
2039 | COMMENT ON RULE name ON any_name IS comment_text
2040 { $$ = cat_str(6, make_str("comment on rule"), $4, make_str("on"), $6, make_str("is"), $8); }
2041 | COMMENT ON RULE name IS comment_text
2042 { $$ = cat_str(4, make_str("comment on rule"), $4, make_str("is"), $6); }
2043 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
2044 { $$ = cat_str(6, make_str("comment on operator class"), $5, make_str("using"), $7, make_str("is"), $9); }
2045 | COMMENT ON LARGE_P OBJECT_P NumConst IS comment_text
2046 { $$ = cat_str(4, make_str("comment on large object"), $5, make_str("is"), $7); }
2047 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
2048 { $$ = cat_str(6, make_str("comment on cast ("), $5, make_str("as"), $7, make_str(") is"), $10); }
2049 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
2050 { $$ = cat_str(6, make_str("comment on"), $3, make_str("language"), $5, make_str("is"), $7); }
2053 comment_type: COLUMN { $$ = make_str("column"); }
2054 | DATABASE { $$ = make_str("database"); }
2055 | SCHEMA { $$ = make_str("schema"); }
2056 | INDEX { $$ = make_str("idnex"); }
2057 | SEQUENCE { $$ = make_str("sequence"); }
2058 | TABLE { $$ = make_str("table"); }
2059 | DOMAIN_P { $$ = make_str("domain"); }
2060 | TYPE_P { $$ = make_str("type"); }
2061 | VIEW { $$ = make_str("view"); }
2062 | CONVERSION_P { $$ = make_str("conversion"); }
2065 comment_text: StringConst { $$ = $1; }
2066 | NULL_P { $$ = make_str("null"); }
2069 /*****************************************************************************
2072 * GRANT and REVOKE statements
2074 *****************************************************************************/
2076 GrantStmt: GRANT privileges ON privilege_target TO grantee_list opt_grant_grant_option
2077 { $$ = cat_str(7, make_str("grant"), $2, make_str("on"), $4, make_str("to"), $6, $7); }
2080 RevokeStmt: REVOKE opt_revoke_grant_option privileges ON privilege_target FROM grantee_list opt_drop_behavior
2082 $$ = cat_str(9, make_str("revoke"), $2, $3, make_str("on"), $5, make_str("from"), $7, $8);
2087 privileges: ALL PRIVILEGES { $$ = make_str("all privileges"); }
2088 | ALL { $$ = make_str("all"); }
2089 | privilege_list { $$ = $1; }
2092 privilege_list: privilege
2094 | privilege_list ',' privilege
2095 { $$ = cat_str(3, $1, make_str(","), $3); }
2098 privilege: SELECT { $$ = make_str("select"); }
2099 | INSERT { $$ = make_str("insert"); }
2100 | UPDATE { $$ = make_str("update"); }
2101 | DELETE_P { $$ = make_str("delete"); }
2102 | RULE { $$ = make_str("rule"); }
2103 | REFERENCES { $$ = make_str("references"); }
2104 | TRIGGER { $$ = make_str("trigger"); }
2105 | EXECUTE { $$ = make_str("execute"); }
2106 | USAGE { $$ = make_str("usage"); }
2107 | CREATE { $$ = make_str("create"); }
2108 | TEMPORARY { $$ = make_str("temporary"); }
2109 | TEMP { $$ = make_str("temp"); }
2112 privilege_target: qualified_name_list
2114 | TABLE qualified_name_list
2115 { $$ = cat2_str(make_str("table"), $2); }
2116 | FUNCTION function_with_argtypes_list
2117 { $$ = cat2_str(make_str("function"), $2); }
2118 | DATABASE name_list
2119 { $$ = cat2_str(make_str("database"), $2); }
2120 | LANGUAGE name_list
2121 { $$ = cat2_str(make_str("language") , $2); }
2123 { $$ = cat2_str(make_str("schema") , $2); }
2124 | TABLESPACE name_list
2125 { $$ = cat2_str(make_str("tablespace") , $2); }
2128 grantee_list: grantee
2130 | grantee_list ',' grantee
2131 { $$ = cat_str(3, $1, make_str(","), $3); }
2134 grantee: ColId { $$ = $1; }
2135 | GROUP_P ColId { $$ = cat2_str(make_str("group"), $2); }
2138 opt_grant_grant_option: WITH GRANT OPTION
2140 mmerror(PARSE_ERROR, ET_WARNING, "Currently unsupported GRANT/WITH GRANT OPTION will be passed to backend");
2141 $$ = make_str("with grant option");
2143 | /*EMPTY*/ { $$ = EMPTY; }
2146 opt_revoke_grant_option: GRANT OPTION FOR
2148 mmerror(PARSE_ERROR, ET_WARNING, "Currently unsupported REVOKE/GRANT OPTION FOR will be passed to backend");
2149 $$ = make_str("grant option for");
2151 | /*EMPTY*/ { $$ = EMPTY; }
2154 function_with_argtypes_list: function_with_argtypes
2156 | function_with_argtypes_list ',' function_with_argtypes
2157 { $$ = cat_str(3, $1, make_str(","), $3); }
2160 function_with_argtypes: func_name func_args { $$ = cat2_str($1, $2); };
2162 /*****************************************************************************
2165 * create index <indexname> on <relname>
2166 * [ using <access> ] "(" ( <col> | using <opclass> ] )+ ")"
2167 * [ tablespace <tablespacename> ] [ where <predicate> ]
2169 *****************************************************************************/
2171 IndexStmt: CREATE index_opt_unique INDEX index_name ON qualified_name
2172 access_method_clause '(' index_params ')' OptTableSpace where_clause
2173 { $$ = cat_str(12, make_str("create"), $2, make_str("index"), $4, make_str("on"), $6, $7, make_str("("), $9, make_str(")"), $11, $12); }
2176 index_opt_unique: UNIQUE { $$ = make_str("unique"); }
2177 | /*EMPTY*/ { $$ = EMPTY; }
2180 access_method_clause: USING access_method
2181 { $$ = cat2_str(make_str("using"), $2); }
2186 index_params: index_elem { $$ = $1; }
2187 | index_params ',' index_elem { $$ = cat_str(3, $1, make_str(","), $3); }
2190 index_elem: attr_name opt_class
2191 { $$ = cat2_str($1, $2); }
2192 | func_name '(' expr_list ')' opt_class
2193 { $$ = cat_str(5, $1, make_str("("), $3, ")", $5); }
2194 | '(' a_expr ')' opt_class
2195 { $$ = cat_str(4, make_str("("), $2, make_str(")"), $4); }
2198 opt_class: any_name { $$ = $1; }
2199 | USING any_name { $$ = cat2_str(make_str("using"), $2); }
2200 | /*EMPTY*/ { $$ = EMPTY; }
2203 CreateFunctionStmt: CREATE opt_or_replace FUNCTION func_name func_args
2204 RETURNS func_return createfunc_opt_list opt_definition
2205 { $$ = cat_str(8, make_str("create"), $2, make_str("function"), $4, $5, make_str("returns"), $7, $8); }
2208 opt_or_replace: OR REPLACE { $$ = make_str("or replace"); }
2209 | /*EMPTY*/ { $$ = EMPTY; }
2212 func_args: '(' func_args_list ')'
2213 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
2215 { $$ = make_str("()"); }
2218 func_args_list: func_arg
2220 | func_args_list ',' func_arg
2221 { $$ = cat_str(3, $1, make_str(","), $3); }
2224 func_arg: arg_class param_name func_type { $$ = cat_str(3, $1, $2, $3); }
2225 | arg_class func_type { $$ = cat2_str($1, $2); }
2228 arg_class: IN_P { $$ = make_str("in"); }
2231 mmerror(PARSE_ERROR, ET_WARNING, "Currently unsupported CREATE FUNCTION/OUT will be passed to backend");
2233 $$ = make_str("out");
2237 mmerror(PARSE_ERROR, ET_WARNING, "Currently unsupported CREATE FUNCTION/INOUT will be passed to backend");
2239 $$ = make_str("inout");
2245 func_as: StringConst
2247 | StringConst ',' StringConst
2248 { $$ = cat_str(3, $1, make_str(","), $3); }
2251 param_name: function_name { $$ = $1; };
2253 func_return: func_type
2255 /* We can catch over-specified arguments here if we want to,
2256 * but for now better to silently swallow typmod, etc.
2257 * - thomas 2000-03-22
2265 | type_name attrs '%' TYPE_P
2266 { $$ = cat_str(3, $1, $2, make_str("% type")); }
2270 createfunc_opt_list: createfunc_opt_item
2272 | createfunc_opt_list createfunc_opt_item
2273 { $$ = cat2_str($1, $2); }
2276 createfunc_opt_item: AS func_as
2277 { $$ = cat2_str(make_str("as"), $2); }
2278 | LANGUAGE ColId_or_Sconst
2279 { $$ = cat2_str(make_str("language"), $2); }
2281 { $$ = make_str("immutable"); }
2283 { $$ = make_str("stable"); }
2285 { $$ = make_str("volatile"); }
2286 | CALLED ON NULL_P INPUT_P
2287 { $$ = make_str("called on null input"); }
2288 | RETURNS NULL_P ON NULL_P INPUT_P
2289 { $$ = make_str("returns null on null input"); }
2291 { $$ = make_str("strict"); }
2292 | EXTERNAL SECURITY DEFINER
2293 { $$ = make_str("external security definer"); }
2294 | EXTERNAL SECURITY INVOKER
2295 { $$ = make_str("external security invoker"); }
2297 { $$ = make_str("security definer"); }
2299 { $$ = make_str("security invoker"); }
2302 opt_definition: WITH definition { $$ = cat2_str(make_str("with"), $2); }
2303 | /*EMPTY*/ { $$ = EMPTY; }
2306 /*****************************************************************************
2310 * DROP FUNCTION funcname (arg1, arg2, ...)
2311 * DROP AGGREGATE aggname (aggtype)
2312 * DROP OPERATOR opname (leftoperand_typ rightoperand_typ)
2314 *****************************************************************************/
2316 RemoveFuncStmt: DROP FUNCTION func_name func_args opt_drop_behavior
2317 { $$ = cat_str(4, make_str("drop function"), $3, $4, $5); }
2320 RemoveAggrStmt: DROP AGGREGATE func_name '(' aggr_argtype ')' opt_drop_behavior
2321 { $$ = cat_str(6, make_str("drop aggregate"), $3, make_str("("), $5, make_str(")"), $7); }
2324 aggr_argtype: Typename { $$ = $1; }
2325 | '*' { $$ = make_str("*"); }
2329 RemoveOperStmt: DROP OPERATOR all_Op '(' oper_argtypes ')' opt_drop_behavior
2330 { $$ = cat_str(6, make_str("drop operator"), $3, make_str("("), $5, make_str(")"), $7); }
2333 oper_argtypes: Typename
2334 { mmerror(PARSE_ERROR, ET_ERROR, "parser: argument type missing (use NONE for unary operators)"); }
2335 | Typename ',' Typename
2336 { $$ = cat_str(3, $1, make_str(","), $3); }
2337 | NONE ',' Typename /* left unary */
2338 { $$ = cat2_str(make_str("none,"), $3); }
2339 | Typename ',' NONE /* right unary */
2340 { $$ = cat2_str($1, make_str(", none")); }
2346 | ColId '.' any_operator
2347 { $$ = cat_str(3, $1, make_str("."), $3); }
2350 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
2351 WITH FUNCTION function_with_argtypes cast_context
2352 { $$ = cat_str(6, make_str("create cast ("), $4, make_str("as"), $6, make_str(") with function"), $10); }
2353 | CREATE CAST '(' Typename AS Typename ')'
2354 WITHOUT FUNCTION cast_context
2355 { $$ = cat_str(6, make_str("create cast ("), $4, make_str("as"), $6, make_str(") without function"), $10); }
2358 cast_context: AS ASSIGNMENT { $$ = make_str("as assignment"); }
2359 | /*EMPTY*/ { $$ = EMPTY; }
2363 DropCastStmt: DROP CAST '(' Typename AS Typename ')' opt_drop_behavior
2364 { $$ = cat_str(6, make_str("drop cast ("), $4, make_str("as"), $6, make_str(")"), $8); }
2367 /*****************************************************************************
2371 * REINDEX type <typename> [FORCE] [ALL]
2373 *****************************************************************************/
2374 ReindexStmt: REINDEX reindex_type qualified_name opt_force
2375 { $$ = cat_str(4, make_str("reindex"), $2, $3, $4); }
2376 | REINDEX DATABASE name opt_force
2377 { $$ = cat_str(3, make_str("reindex database"), $3, $4); }
2380 reindex_type: INDEX { $$ = make_str("index"); }
2381 | TABLE { $$ = make_str("table"); }
2384 opt_force: FORCE { $$ = make_str("force"); }
2385 | /* EMPTY */ { $$ = EMPTY; }
2388 /*****************************************************************************
2391 * rename <attrname1> in <relname> [*] to <attrname2>
2392 * rename <relname1> to <relname2>
2394 *****************************************************************************/
2396 RenameStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' RENAME TO name
2397 { $$ = cat_str(6, make_str("alter aggregate"), $3, make_str("("), $5, make_str(") rename to"), $9); }
2398 | ALTER CONVERSION_P any_name RENAME TO name
2399 { $$ = cat_str(4, make_str("alter conversion"), $3, make_str("rename to"), $6); }
2400 | ALTER DATABASE database_name RENAME TO database_name
2401 { $$ = cat_str(4, make_str("alter database"), $3, make_str("rename to"), $6); }
2402 | ALTER FUNCTION func_name func_args RENAME TO name
2403 { $$ = cat_str(5, make_str("alter function"), $3, $4, make_str("rename to"), $7); }
2404 | ALTER GROUP_P UserId RENAME TO UserId
2405 { $$ = cat_str(4, make_str("alter group"), $3, make_str("rename to"), $6); }
2406 | ALTER LANGUAGE name RENAME TO name
2407 { $$ = cat_str(4, make_str("alter language"), $3, make_str("rename to"), $6); }
2408 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
2409 { $$ = cat_str(6, make_str("alter operator class"), $4, make_str("using"), $6, make_str("rename to"), $9); }
2410 | ALTER SCHEMA name RENAME TO name
2411 { $$ = cat_str(4, make_str("alter schema"), $3, make_str("rename to"), $6); }
2412 | ALTER TABLE relation_expr RENAME TO name
2413 { $$ = cat_str(4, make_str("alter table"), $3, make_str("rename to"), $6); }
2414 | ALTER TABLE relation_expr RENAME opt_column name TO name
2415 { $$ = cat_str(7, make_str("alter table"), $3, make_str("rename"), $5, $6, make_str("to"), $8); }
2416 | ALTER TRIGGER name ON relation_expr RENAME TO name
2417 { $$ = cat_str(6, make_str("alter trigger"), $3, make_str("on"), $5, make_str("rename to"), $8); }
2418 | ALTER USER UserId RENAME TO UserId
2419 { $$ = cat_str(4, make_str("alter user"), $3, make_str("rename to"), $6); }
2420 | ALTER TABLESPACE name RENAME TO name
2421 { $$ = cat_str(4, make_str("alter tablespace"), $3, make_str("rename to"), $6); }
2424 opt_column: COLUMN { $$ = make_str("column"); }
2425 | /*EMPTY*/ { $$ = EMPTY; }
2428 /*****************************************************************************
2430 * ALTER THING name OWNER TO newname.
2432 *****************************************************************************/
2434 AlterOwnerStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' OWNER TO UserId
2435 { $$ = cat_str(6, make_str("alter aggregate"), $3, make_str("("), $5, make_str(") owner to"), $9); }
2436 | ALTER CONVERSION_P any_name OWNER TO UserId
2437 { $$ = cat_str(4, make_str("alter conversion"), $3, make_str("owner to"), $6); }
2438 | ALTER DATABASE database_name OWNER TO UserId
2439 { $$ = cat_str(4, make_str("alter database"), $3, make_str("owner to"), $6); }
2440 | ALTER DOMAIN_P database_name OWNER TO UserId
2441 { $$ = cat_str(4, make_str("alter domain"), $3, make_str("owner to"), $6); }
2442 | ALTER FUNCTION func_name func_args OWNER TO UserId
2443 { $$ = cat_str(5, make_str("alter function"), $3, $4, make_str("owner to"), $7); }
2444 | ALTER OPERATOR any_operator '(' oper_argtypes ')' OWNER TO UserId
2445 { $$ = cat_str(6, make_str("alter operator"), $3, make_str("("), $5, make_str(") owner to"), $9); }
2446 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO UserId
2447 { $$ = cat_str(6, make_str("alter operator class"), $4, make_str("using"), $6, make_str("owner to"), $9); }
2448 | ALTER SCHEMA name OWNER TO UserId
2449 { $$ = cat_str(4, make_str("alter schema"), $3, make_str("owner to"), $6); }
2450 | ALTER TYPE_P any_name OWNER TO UserId
2451 { $$ = cat_str(4, make_str("alter type"), $3, make_str("owner to"), $6); }
2452 | ALTER TABLESPACE name OWNER TO UserId
2453 { $$ = cat_str(4, make_str("alter tablespace"), $3, make_str("owner to"), $6); }
2457 /*****************************************************************************
2459 * QUERY: Define Rewrite Rule
2461 *****************************************************************************/
2463 RuleStmt: CREATE opt_or_replace RULE name AS
2465 ON event TO qualified_name where_clause
2466 DO opt_instead RuleActionList
2469 $$ = cat_str(12, make_str("create"), $2, make_str("rule"), $4, make_str("as on"), $8, make_str("to"), $10, $11, make_str("do"), $13, $14);
2473 RuleActionList: NOTHING { $$ = make_str("nothing"); }
2474 | RuleActionStmt { $$ = $1; }
2475 | '(' RuleActionMulti ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
2478 /* the thrashing around here is to discard "empty" statements... */
2479 RuleActionMulti: RuleActionMulti ';' RuleActionStmtOrEmpty
2480 { $$ = cat_str(3, $1, make_str(";"), $3); }
2481 | RuleActionStmtOrEmpty
2482 { $$ = cat2_str($1, make_str(";")); }
2485 RuleActionStmt: SelectStmt
2492 RuleActionStmtOrEmpty: RuleActionStmt { $$ = $1; }
2493 | /*EMPTY*/ { $$ = EMPTY; }
2496 /* change me to select, update, etc. some day */
2497 event: SELECT { $$ = make_str("select"); }
2498 | UPDATE { $$ = make_str("update"); }
2499 | DELETE_P { $$ = make_str("delete"); }
2500 | INSERT { $$ = make_str("insert"); }
2503 opt_instead: INSTEAD { $$ = make_str("instead"); }
2504 | ALSO { $$ = make_str("also"); }
2505 | /*EMPTY*/ { $$ = EMPTY; }
2508 DropRuleStmt: DROP RULE name ON qualified_name opt_drop_behavior
2509 { $$ = cat_str(5, make_str("drop rule"), $3, make_str("on"), $5, $6);}
2512 /*****************************************************************************
2515 * NOTIFY <qualified_name> can appear both in rule bodies and
2516 * as a query-level command
2518 *****************************************************************************/
2520 NotifyStmt: NOTIFY qualified_name
2521 { $$ = cat2_str(make_str("notify"), $2); }
2524 ListenStmt: LISTEN qualified_name
2525 { $$ = cat2_str(make_str("listen"), $2); }
2528 UnlistenStmt: UNLISTEN qualified_name
2529 { $$ = cat2_str(make_str("unlisten"), $2); }
2531 { $$ = make_str("unlisten *"); }
2535 /*****************************************************************************
2539 * BEGIN / COMMIT / ROLLBACK
2540 * (also older versions END / ABORT)
2542 *****************************************************************************/
2543 TransactionStmt: ABORT_P opt_transaction { $$ = make_str("rollback"); }
2544 | BEGIN_P opt_transaction transaction_mode_list_or_empty { $$ = cat2_str(make_str("begin transaction"), $3); }
2545 | START TRANSACTION transaction_mode_list_or_empty { $$ = cat2_str(make_str("start transaction"), $3); }
2546 | COMMIT opt_transaction { $$ = make_str("commit"); }
2547 | END_P opt_transaction { $$ = make_str("commit"); }
2548 | ROLLBACK opt_transaction { $$ = make_str("rollback"); }
2551 opt_transaction: WORK { $$ = EMPTY; }
2552 | TRANSACTION { $$ = EMPTY; }
2553 | /*EMPTY*/ { $$ = EMPTY; }
2556 transaction_mode_list:
2557 ISOLATION LEVEL iso_level
2558 { $$ = cat2_str(make_str("isolation level"), $3); }
2559 | transaction_access_mode
2561 | ISOLATION LEVEL iso_level transaction_access_mode
2562 { $$ = cat_str(3, make_str("isolation level"), $3, $4); }
2563 | transaction_access_mode ISOLATION LEVEL iso_level
2564 { $$ = cat_str(3, $1, make_str("isolation level"), $4); }
2567 transaction_mode_list_or_empty:
2568 transaction_mode_list { $$ = $1; }
2569 | /* EMPTY */ { $$ = EMPTY; }
2572 transaction_access_mode:
2573 READ ONLY { $$ = make_str("read only"); }
2574 | READ WRITE { $$ = make_str("read write"); }
2577 /*****************************************************************************
2580 * define view <viewname> '('target-list ')' [where <quals> ]
2582 *****************************************************************************/
2584 ViewStmt: CREATE opt_or_replace VIEW qualified_name opt_column_list AS SelectStmt
2585 { $$ = cat_str(7, make_str("create"), $2, make_str("view"), $4, $5, make_str("as"), $7); }
2589 /*****************************************************************************
2592 * load make_str("filename")
2594 *****************************************************************************/
2596 LoadStmt: LOAD file_name
2597 { $$ = cat2_str(make_str("load"), $2); }
2601 /*****************************************************************************
2606 *****************************************************************************/
2608 CreatedbStmt: CREATE DATABASE database_name WITH createdb_opt_list
2609 { $$ = cat_str(4, make_str("create database"), $3, make_str("with"), $5); }
2610 | CREATE DATABASE database_name
2611 { $$ = cat2_str(make_str("create database"), $3); }
2614 createdb_opt_list: createdb_opt_item
2616 | createdb_opt_list createdb_opt_item
2617 { $$ = cat2_str($1, $2); }
2620 createdb_opt_item: TABLESPACE opt_equal name
2621 { $$ = cat_str(3,make_str("tablespace"), $2, $3); }
2622 | TABLESPACE opt_equal DEFAULT
2623 { $$ = cat_str(3, make_str("tablespace"), $2, make_str("default")); }
2624 | LOCATION opt_equal StringConst
2625 { $$ = cat_str(3,make_str("location"), $2, $3); }
2626 | LOCATION opt_equal DEFAULT
2627 { $$ = cat_str(3, make_str("location"), $2, make_str("default")); }
2628 | TEMPLATE opt_equal name
2629 { $$ = cat_str(3, make_str("template"), $2, $3); }
2630 | TEMPLATE opt_equal DEFAULT
2631 { $$ = cat_str(3, make_str("template"), $2, make_str("default")); }
2632 | ENCODING opt_equal PosIntStringConst
2633 { $$ = cat_str(3, make_str("encoding"), $2, $3); }
2634 | ENCODING opt_equal DEFAULT
2635 { $$ = cat_str(3, make_str("encoding"), $2, make_str("default")); }
2636 | OWNER opt_equal name
2637 { $$ = cat_str(3, make_str("owner"), $2, $3); }
2638 | OWNER opt_equal DEFAULT
2639 { $$ = cat_str(3, make_str("owner"), $2, make_str("default")); }
2642 opt_equal: '=' { $$ = make_str("="); }
2643 | /* EMPTY */ { $$ = EMPTY; }
2647 /*****************************************************************************
2652 *****************************************************************************/
2654 AlterDatabaseSetStmt: ALTER DATABASE database_name SET set_rest
2655 { $$ = cat_str(4, make_str("alter database"), $3, make_str("set"), $5); }
2656 | ALTER DATABASE database_name VariableResetStmt
2657 { $$ = cat_str(3, make_str("alter database"), $3, $4); }
2660 /*****************************************************************************
2665 *****************************************************************************/
2667 DropdbStmt: DROP DATABASE database_name
2668 { $$ = cat2_str(make_str("drop database"), $3); }
2672 /*****************************************************************************
2674 * Manipulate a domain
2676 *****************************************************************************/
2678 CreateDomainStmt: CREATE DOMAIN_P any_name opt_as Typename ColQualList
2680 $$ = cat_str(55555, make_str("create domain"), $3, $4, $5, $6);
2685 ALTER DOMAIN_P any_name alter_column_default
2686 { $$ = cat_str(3, make_str("alter domain"), $3, $4); }
2687 | ALTER DOMAIN_P any_name DROP NOT NULL_P
2688 { $$ = cat_str(3, make_str("alter domain"), $3, make_str("drop not null")); }
2689 | ALTER DOMAIN_P any_name SET NOT NULL_P
2690 { $$ = cat_str(3, make_str("alter domain"), $3, make_str("set not null")); }
2691 | ALTER DOMAIN_P any_name ADD TableConstraint
2692 { $$ = cat_str(4, make_str("alter domain"), $3, make_str("add"), $5); }
2693 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
2694 { $$ = cat_str(5, make_str("alter domain"), $3, make_str("drop constraint"), $6, $7); }
2697 opt_as: AS {$$ = make_str("as"); }
2698 | /* EMPTY */ {$$ = EMPTY; }
2701 CreateConversionStmt:
2702 CREATE opt_default CONVERSION_P any_name FOR StringConst
2703 TO StringConst FROM any_name
2704 { $$ = cat_str(10, make_str("create"), $2, make_str("conversion"), $4, make_str("for"), $6, make_str("to"), $8, make_str("from"), $10); }
2707 /*****************************************************************************
2710 * cluster <index_name> on <qualified_name>
2711 * cluster <qualified_name>
2714 *****************************************************************************/
2716 ClusterStmt: CLUSTER index_name ON qualified_name
2717 { $$ = cat_str(4, make_str("cluster"), $2, make_str("on"), $4); }
2718 | CLUSTER qualified_name
2719 { $$ = cat2_str(make_str("cluster"), $2); }
2721 { $$ = make_str("cluster"); }
2725 /*****************************************************************************
2731 *****************************************************************************/
2733 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
2734 { $$ = cat_str(4, make_str("vacuum"), $2, $3, $4); }
2735 | VACUUM opt_full opt_freeze opt_verbose qualified_name
2736 { $$ = cat_str(5, make_str("vacuum"), $2, $3, $4, $5); }
2737 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
2738 { $$ = cat_str(5, make_str("vacuum"), $2, $3, $4, $5); }
2741 AnalyzeStmt: analyze_keyword opt_verbose
2742 { $$ = cat_str(2, $1, $2); }
2743 | analyze_keyword opt_verbose qualified_name opt_name_list
2744 { $$ = cat_str(4, $1, $2, $3, $4); }
2747 analyze_keyword: ANALYZE { $$ = make_str("analyze"); }
2748 | ANALYSE { $$ = make_str("analyse"); }
2751 opt_verbose: VERBOSE { $$ = make_str("verbose"); }
2752 | /*EMPTY*/ { $$ = EMPTY; }
2755 opt_full: FULL { $$ = make_str("full"); }
2756 | /*EMPTY*/ { $$ = EMPTY; }
2759 opt_freeze: FREEZE { $$ = make_str("freeze"); }
2760 | /*EMPTY*/ { $$ = EMPTY; }
2763 opt_name_list: '(' name_list ')'
2764 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
2770 /*****************************************************************************
2775 *****************************************************************************/
2777 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
2778 { $$ = cat_str(4, make_str("explain"), $2, $3, $4); }
2790 analyze_keyword { $$ = $1; }
2791 | /* EMPTY */ { $$ = EMPTY; }
2798 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
2799 { $$ = cat_str(5, make_str("prepare"), $2, $3, make_str("as"), $5); }
2809 prep_type_clause: '(' prep_type_list ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
2810 | /* EMPTY * / { $$ = EMPTY; }
2813 prep_type_list: Typename { $$ = $1; }
2814 | prep_type_list ',' Typename { $$ = cat_str(3, $1, make_str(","), $3); }
2817 ExecuteStmt: EXECUTE name execute_param_clause
2818 { $$ = cat_str(3, make_str("execute"), $2, $3); }
2819 | CREATE OptTemp TABLE qualified_name OptCreateAs AS EXECUTE name execute_param_clause
2820 { $$ = cat_str(8, make_str("create"), $2, make_str("table"), $4, $5, make_str("as execute"), $8, $9); }
2824 execute_param_clause: '(' expr_list ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
2825 | /* EMPTY * / { $$ = EMPTY; }
2828 DeallocateStmt: DEALLOCATE name { $$ = cat2_str(make_str("deallocate"), $2); }
2829 | DEALLOCATE PREPARE name { $$ = cat2_str(make_str("deallocate prepare"), $3); }
2833 /*****************************************************************************
2838 *****************************************************************************/
2840 InsertStmt: INSERT INTO qualified_name insert_rest
2841 { $$ = cat_str(3, make_str("insert into"), $3, $4); }
2844 insert_rest: VALUES '(' insert_target_list ')'
2845 { $$ = cat_str(3, make_str("values("), $3, make_str(")")); }
2847 { $$ = make_str("default values"); }
2850 | '(' insert_column_list ')' VALUES '(' insert_target_list ')'
2851 { $$ = cat_str(5, make_str("("), $2, make_str(") values ("), $6, make_str(")")); }
2852 | '(' insert_column_list ')' SelectStmt
2853 { $$ = cat_str(4, make_str("("), $2, make_str(")"), $4); }
2856 insert_column_list: insert_column_list ',' insert_column_item
2857 { $$ = cat_str(3, $1, make_str(","), $3); }
2858 | insert_column_item
2862 insert_column_item: ColId opt_indirection
2863 { $$ = cat2_str($1, $2); }
2867 /*****************************************************************************
2872 *****************************************************************************/
2874 DeleteStmt: DELETE_P FROM relation_expr where_clause
2875 { $$ = cat_str(3, make_str("delete from"), $3, $4); }
2878 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
2879 { $$ = cat_str(5, make_str("lock"), $2, $3, $4, $5); }
2882 opt_lock: IN_P lock_type MODE
2883 { $$ = cat_str(3, make_str("in"), $2, make_str("mode")); }
2888 lock_type: ACCESS SHARE { $$ = make_str("access share"); }
2889 | ROW SHARE { $$ = make_str("access share"); }
2890 | ROW EXCLUSIVE { $$ = make_str("row exclusive"); }
2891 | SHARE UPDATE EXCLUSIVE { $$ = make_str("share update exclusive"); }
2892 | SHARE { $$ = make_str("share"); }
2893 | SHARE ROW EXCLUSIVE { $$ = make_str("share row exclusive"); }
2894 | EXCLUSIVE { $$ = make_str("exclusive"); }
2895 | ACCESS EXCLUSIVE { $$ = make_str("access exclusive"); }
2898 opt_nowait: NOWAIT { $$ = make_str("nowait"); }
2899 | /* EMPTY */ { $$ = EMPTY; }
2902 /*****************************************************************************
2905 * UpdateStmt (UPDATE)
2907 *****************************************************************************/
2909 UpdateStmt: UPDATE relation_expr
2910 SET update_target_list
2913 {$$ = cat_str(6, make_str("update"), $2, make_str("set"), $4, $5, $6); }
2917 /*****************************************************************************
2922 *****************************************************************************/
2923 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
2925 struct cursor *ptr, *this;
2927 for (ptr = cur; ptr != NULL; ptr = ptr->next)
2929 if (strcmp($2, ptr->name) == 0)
2930 /* re-definition is a bug */
2931 mmerror(PARSE_ERROR, ET_ERROR, "cursor %s already defined", $2);
2934 this = (struct cursor *) mm_alloc(sizeof(struct cursor));
2936 /* initial definition */
2939 this->connection = connection;
2940 this->opened = false;
2941 this->command = cat_str(7, make_str("declare"), mm_strdup($2), $3, make_str("cursor"), $5, make_str("for"), $7);
2942 this->argsinsert = argsinsert;
2943 this->argsresult = argsresult;
2944 argsinsert = argsresult = NULL;
2948 $$ = cat_str(5, adjust_informix(this->argsinsert), adjust_informix(this->argsresult), make_str("/*"), mm_strdup(this->command), make_str("*/"));
2950 $$ = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
2954 cursor_options: /* EMPTY */ { $$ = EMPTY; }
2955 | cursor_options BINARY { $$ = cat2_str($1, make_str("binary")); }
2956 | cursor_options INSENSITIVE { $$ = cat2_str($1, make_str("insensitive")); }
2957 | cursor_options SCROLL { $$ = cat2_str($1, make_str("scroll")); }
2958 | cursor_options NO SCROLL { $$ = cat2_str($1, make_str("no scroll")); }
2961 opt_hold: /* EMPTY */ { if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit == true)
2962 $$ = make_str("with hold");
2965 | WITH HOLD { $$ = make_str("with hold"); }
2966 | WITHOUT HOLD { $$ = make_str("without hold"); }
2969 /*****************************************************************************
2974 *****************************************************************************/
2976 SelectStmt: select_no_parens %prec UMINUS
2978 | select_with_parens %prec UMINUS
2982 select_with_parens: '(' select_no_parens ')'
2983 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
2984 | '(' select_with_parens ')'
2985 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
2988 select_no_parens: simple_select
2990 | select_clause sort_clause
2991 { $$ = cat2_str($1, $2); }
2992 | select_clause opt_sort_clause for_update_clause opt_select_limit
2993 { $$ = cat_str(4, $1, $2, $3, $4); }
2994 | select_clause opt_sort_clause select_limit opt_for_update_clause
2995 { $$ = cat_str(4, $1, $2, $3, $4); }
2998 select_clause: simple_select { $$ = $1; }
2999 | select_with_parens { $$ = $1; }
3002 simple_select: SELECT opt_distinct target_list
3003 into_clause from_clause where_clause
3004 group_clause having_clause
3005 { $$ = cat_str(8, make_str("select"), $2, $3, $4, $5, $6, $7, $8); }
3006 | select_clause UNION opt_all select_clause
3007 { $$ = cat_str(4, $1, make_str("union"), $3, $4); }
3008 | select_clause INTERSECT opt_all select_clause
3009 { $$ = cat_str(4, $1, make_str("intersect"), $3, $4); }
3010 | select_clause EXCEPT opt_all select_clause
3011 { $$ = cat_str(4, $1, make_str("except"), $3, $4); }
3014 into_clause: INTO OptTempTableName
3017 $$= cat2_str(make_str("into"), $2);
3019 | ecpg_into { $$ = EMPTY; }
3020 | /*EMPTY*/ { $$ = EMPTY; }
3024 * Redundancy here is needed to avoid shift/reduce conflicts,
3025 * since TEMP is not a reserved word. See also OptTemp.
3027 * The result is a cons cell (not a true list!) containing
3028 * a boolean and a table name.
3030 OptTempTableName: TEMPORARY opt_table qualified_name
3031 { $$ = cat_str(3, make_str("temporary"), $2, $3); }
3032 | TEMP opt_table qualified_name
3033 { $$ = cat_str(3, make_str("temp"), $2, $3); }
3034 | LOCAL TEMPORARY opt_table qualified_name
3035 { $$ = cat_str(3, make_str("local temporary"), $3, $4); }
3036 | LOCAL TEMP opt_table qualified_name
3037 { $$ = cat_str(3, make_str("local temp"), $3, $4); }
3038 | GLOBAL TEMPORARY opt_table qualified_name
3039 { $$ = cat_str(3, make_str("global temporary"), $3, $4); }
3040 | GLOBAL TEMP opt_table qualified_name
3041 { $$ = cat_str(3, make_str("global temp"), $3, $4); }
3042 | TABLE qualified_name
3043 { $$ = cat2_str(make_str("table"), $2); }
3048 opt_table: TABLE { $$ = make_str("table"); }
3049 | /*EMPTY*/ { $$ = EMPTY; }
3052 opt_all: ALL { $$ = make_str("all"); }
3053 | /*EMPTY*/ { $$ = EMPTY; }
3056 opt_distinct: DISTINCT
3057 { $$ = make_str("distinct"); }
3058 | DISTINCT ON '(' expr_list ')'
3059 { $$ = cat_str(3, make_str("distinct on ("), $4, make_str(")")); }
3061 { $$ = make_str("all"); }
3066 opt_sort_clause: sort_clause { $$ = $1; }
3067 | /* EMPTY */ { $$ = EMPTY; }
3070 sort_clause: ORDER BY sortby_list
3071 { $$ = cat2_str(make_str("order by"), $3); }
3074 sortby_list: sortby { $$ = $1; }
3075 | sortby_list ',' sortby { $$ = cat_str(3, $1, make_str(","), $3); }
3078 sortby: a_expr USING qual_all_Op
3079 { $$ = cat_str(3, $1, make_str("using"), $3); }
3081 { $$ = cat2_str($1, make_str("asc")); }
3083 { $$ = cat2_str($1, make_str("desc")); }
3088 select_limit: LIMIT select_limit_value OFFSET select_offset_value
3089 { $$ = cat_str(4, make_str("limit"), $2, make_str("offset"), $4); }
3090 | OFFSET select_offset_value LIMIT select_limit_value
3091 { $$ = cat_str(4, make_str("offset"), $2, make_str("limit"), $4); }
3092 | LIMIT select_limit_value
3093 { $$ = cat2_str(make_str("limit"), $2); }
3094 | OFFSET select_offset_value
3095 { $$ = cat2_str(make_str("offset"), $2); }
3096 | LIMIT select_limit_value ',' select_offset_value
3097 { mmerror(PARSE_ERROR, ET_WARNING, "No longer supported LIMIT #,# syntax passed to backend."); }
3100 opt_select_limit: select_limit { $$ = $1; }
3101 | /*EMPTY*/ { $$ = EMPTY; }
3104 select_limit_value: a_expr { $$ = $1; }
3105 | ALL { $$ = make_str("all"); }
3108 select_offset_value: a_expr { $$ = $1; }
3112 * jimmy bell-style recursive queries aren't supported in the
3115 * ...however, recursive addattr and rename supported. make special
3118 group_clause: GROUP_P BY expr_list
3119 { $$ = cat2_str(make_str("group by"), $3); }
3124 having_clause: HAVING a_expr
3125 { $$ = cat2_str(make_str("having"), $2); }
3130 for_update_clause: FOR UPDATE update_list
3131 { $$ = make_str("for update"); }
3133 { $$ = make_str("for read only"); }
3136 opt_for_update_clause: for_update_clause { $$ = $1; }
3137 | /* EMPTY */ { $$ = EMPTY; }
3140 update_list: OF name_list { $$ = cat2_str(make_str("of"), $2); }
3141 | /* EMPTY */ { $$ = EMPTY; }
3144 /*****************************************************************************
3146 * clauses common to all Optimizable Stmts:
3147 * from_clause - allow list of both JOIN expressions and table names
3148 * where_clause - qualifications for joins or restrictions
3150 *****************************************************************************/
3152 from_clause: FROM from_list { $$ = cat2_str(make_str("from"), $2); }
3153 | /* EMPTY */ { $$ = EMPTY; }
3156 from_list: from_list ',' table_ref { $$ = cat_str(3, $1, make_str(","), $3); }
3157 | table_ref { $$ = $1; }
3161 * table_ref is where an alias clause can be attached. Note we cannot make
3162 * alias_clause have an empty production because that causes parse conflicts
3163 * between table_ref := '(' joined_table ')' alias_clause
3164 * and joined_table := '(' joined_table ')'. So, we must have the
3165 * redundant-looking productions here instead.
3167 table_ref: relation_expr
3169 | relation_expr alias_clause
3170 { $$= cat2_str($1, $2); }
3173 | func_table alias_clause
3174 { $$= cat2_str($1, $2); }
3175 | func_table AS '(' TableFuncElementList ')'
3176 { $$=cat_str(4, $1, make_str("as ("), $4, make_str(")")); }
3177 | func_table AS ColId '(' TableFuncElementList ')'
3178 { $$=cat_str(6, $1, make_str("as"), $3, make_str("("), $5, make_str(")"));}
3179 | func_table ColId '(' TableFuncElementList ')'
3180 { $$=cat_str(5, $1, $2, make_str("("), $4, make_str(")")); }
3181 | select_with_parens
3182 {mmerror(PARSE_ERROR, ET_ERROR, "sub-SELECT in FROM must have an alias");}
3183 | select_with_parens alias_clause
3184 { $$=cat2_str($1, $2); }
3187 | '(' joined_table ')' alias_clause
3188 { $$=cat_str(4, make_str("("), $2, make_str(")"), $4); }
3192 * It may seem silly to separate joined_table from table_ref, but there is
3193 * method in SQL92's madness: if you don't do it this way you get reduce-
3194 * reduce conflicts, because it's not clear to the parser generator whether
3195 * to expect alias_clause after ')' or not. For the same reason we must
3196 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
3197 * join_type to expand to empty; if we try it, the parser generator can't
3198 * figure out when to reduce an empty join_type right after table_ref.
3200 * Note that a CROSS JOIN is the same as an unqualified
3201 * INNER JOIN, and an INNER JOIN/ON has the same shape
3202 * but a qualification expression to limit membership.
3203 * A NATURAL JOIN implicitly matches column names between
3204 * tables and the shape is determined by which columns are
3205 * in common. We'll collect columns during the later transformations.
3208 joined_table: '(' joined_table ')'
3209 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
3210 | table_ref CROSS JOIN table_ref
3211 { $$ = cat_str(3, $1, make_str("cross join"), $4); }
3212 | table_ref UNIONJOIN table_ref
3213 { $$ = cat_str(3, $1, make_str("unionjoin"), $3); }
3214 | table_ref join_type JOIN table_ref join_qual
3215 { $$ = cat_str(5, $1, $2, make_str("join"), $4, $5); }
3216 | table_ref JOIN table_ref join_qual
3217 { $$ = cat_str(4, $1, make_str("join"), $3, $4); }
3218 | table_ref NATURAL join_type JOIN table_ref
3219 { $$ = cat_str(5, $1, make_str("natural"), $3, make_str("join"), $5); }
3220 | table_ref NATURAL JOIN table_ref
3221 { $$ = cat_str(3, $1, make_str("natural join"), $4); }
3224 alias_clause: AS ColId '(' name_list ')'
3225 { $$ = cat_str(5, make_str("as"), $2, make_str("("), $4, make_str(")")); }
3227 { $$ = cat2_str(make_str("as"), $2); }
3228 | ColId '(' name_list ')'
3229 { $$ = cat_str(4, $1, make_str("("), $3, make_str(")")); }
3234 join_type: FULL join_outer { $$ = cat2_str(make_str("full"), $2); }
3235 | LEFT join_outer { $$ = cat2_str(make_str("left"), $2); }
3236 | RIGHT join_outer { $$ = cat2_str(make_str("right"), $2); }
3237 | INNER_P { $$ = make_str("inner"); }
3240 /* OUTER is just noise... */
3241 join_outer: OUTER_P { $$ = make_str("outer"); }
3242 | /*EMPTY*/ { $$ = EMPTY; /* no qualifiers */ }
3245 /* JOIN qualification clauses
3246 * Possibilities are:
3247 * USING ( column list ) allows only unqualified column names,
3248 * which must match between tables.
3249 * ON expr allows more general qualifications.
3252 join_qual: USING '(' name_list ')'
3253 { $$ = cat_str(3, make_str("using ("), $3, make_str(")")); }
3255 { $$ = cat2_str(make_str("on"), $2); }
3258 relation_expr: qualified_name
3259 { /* normal relations */ $$ = $1; }
3260 | qualified_name '*'
3261 { /* inheritance query */ $$ = cat2_str($1, make_str("*")); }
3262 | ONLY qualified_name
3263 { /* inheritance query */ $$ = cat2_str(make_str("only "), $2); }
3264 | ONLY '(' qualified_name ')'
3265 { /* inheritance query */ $$ = cat_str(3, make_str("only ("), $3, make_str(")")); }
3268 func_table: func_name '(' ')'
3269 { $$ = cat2_str($1, make_str("()")); }
3270 | func_name '(' expr_list ')'
3271 { $$ = cat_str(4, $1, make_str("("), $3, make_str(")")); }
3274 where_clause: WHERE a_expr { $$ = cat2_str(make_str("where"), $2); }
3275 | /*EMPTY*/ { $$ = EMPTY; /* no qualifiers */ }
3278 TableFuncElementList: TableFuncElement
3280 | TableFuncElementList ',' TableFuncElement
3281 { $$ = cat_str(3, $1, make_str(","), $3); }
3284 TableFuncElement: ColId Typename { $$ = cat2_str($1, $2); }
3287 /*****************************************************************************
3290 * SQL92 introduces a large amount of type-specific syntax.
3291 * Define individual clauses to handle these cases, and use
3292 * the generic case to handle regular type-extensible Postgres syntax.
3293 * - thomas 1997-10-10
3295 *****************************************************************************/
3297 Typename: SimpleTypename opt_array_bounds
3298 { $$ = cat2_str($1, $2.str); }
3299 | SETOF SimpleTypename opt_array_bounds
3300 { $$ = cat_str(3, make_str("setof"), $2, $3); }
3301 | SimpleTypename ARRAY '[' PosIntConst ']'
3302 { $$ = cat_str(4, $1, make_str("array ["), $4, make_str("]")); }
3303 | SETOF SimpleTypename ARRAY '[' PosIntConst ']'
3304 { $$ = cat_str(5, make_str("setof"), $2, make_str("array ["), $5, make_str("]")); }
3308 opt_array_bounds: '[' ']' opt_array_bounds
3310 $$.index1 = make_str("0");
3311 $$.index2 = $3.index1;
3312 $$.str = cat2_str(make_str("[]"), $3.str);
3314 | '[' Iresult ']' opt_array_bounds
3316 $$.index1 = strdup($2);
3317 $$.index2 = $4.index1;
3318 $$.str = cat_str(4, make_str("["), $2, make_str("]"), $4.str);
3322 $$.index1 = make_str("-1");
3323 $$.index2 = make_str("-1");
3328 Iresult: PosIntConst { $$ = $1; }
3329 | '(' Iresult ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
3330 | Iresult '+' Iresult { $$ = cat_str(3, $1, make_str("+"), $3); }
3331 | Iresult '-' Iresult { $$ = cat_str(3, $1, make_str("-"), $3); }
3332 | Iresult '*' Iresult { $$ = cat_str(3, $1, make_str("*"), $3); }
3333 | Iresult '/' Iresult { $$ = cat_str(3, $1, make_str("/"), $3); }
3334 | Iresult '%' Iresult { $$ = cat_str(3, $1, make_str("%"), $3); }
3335 | Sconst { $$ = $1; }
3336 | ColId { $$ = $1; }
3339 SimpleTypename: GenericType { $$ = $1; }
3340 | ConstDatetime { $$ = $1; }
3341 | Numeric { $$ = $1; }
3343 | Character { $$ = $1; }
3344 | ConstInterval opt_interval
3345 { $$ = cat2_str($1, $2); }
3346 | ConstInterval '(' PosIntConst ')' opt_interval
3347 { $$ = cat_str(5, $1, make_str("("), $3, make_str(")"), $5); }
3349 { $$ = cat2_str($1, $2);}
3352 ConstTypename: GenericType { $$ = $1; }
3353 | ConstDatetime { $$ = $1; }
3354 | Numeric { $$ = $1; }
3355 | ConstBit { $$ = $1; }
3356 | ConstCharacter { $$ = $1; }
3359 GenericType: type_name { $$ = $1; }
3362 /* SQL92 numeric data types
3363 * Check FLOAT() precision limits assuming IEEE floating types.
3364 * Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
3365 * - thomas 1997-09-18
3368 { $$ = make_str("int"); }
3370 { $$ = make_str("integer"); }
3372 { $$ = make_str("smallint"); }
3374 { $$ = make_str("bigint"); }
3376 { $$ = make_str("real"); }
3378 { $$ = cat2_str(make_str("float"), $2); }
3379 | DOUBLE_P PRECISION
3380 { $$ = make_str("double precision"); }
3381 | DECIMAL_P opt_decimal
3382 { $$ = cat2_str(make_str("decimal"), $2); }
3384 { $$ = cat2_str(make_str("dec"), $2); }
3385 | NUMERIC opt_numeric
3386 { $$ = cat2_str(make_str("numeric"), $2); }
3388 { $$ = make_str("boolean"); }
3391 opt_float: '(' PosIntConst ')'
3392 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
3397 opt_numeric: '(' PosIntConst ',' PosIntConst ')'
3398 { $$ = cat_str(5, make_str("("), $2, make_str(","), $4, make_str(")")); }
3399 | '(' PosIntConst ')'
3400 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
3405 opt_decimal: '(' PosIntConst ',' PosIntConst ')'
3406 { $$ = cat_str(5, make_str("("), $2, make_str(","), $4, make_str(")")); }
3407 | '(' PosIntConst ')'
3408 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
3414 * SQL92 bit-field data types
3415 * The following implements BIT() and BIT VARYING().
3418 Bit: BitWithLength { $$ = $1; }
3419 | BitWithoutLength { $$ = $1; }
3422 ConstBit: BitWithLength { $$ = $1; }
3423 | BitWithoutLength { $$ = $1; }
3426 BitWithLength: BIT opt_varying '(' PosIntConst ')'
3427 { $$ = cat_str(5, make_str("bit"), $2, make_str("("), $4, make_str(")")); }
3430 BitWithoutLength: BIT opt_varying
3431 { $$ = cat2_str(make_str("bit"), $2); }
3435 * SQL92 character data types
3436 * The following implements CHAR() and VARCHAR().
3439 Character: CharacterWithLength { $$ = $1; }
3440 | CharacterWithoutLength { $$ = $1; }
3443 ConstCharacter: CharacterWithLength { $$ = $1; }
3444 | CharacterWithoutLength { $$ = $1; }
3447 CharacterWithLength: character '(' PosIntConst ')' opt_charset
3448 { $$ = cat_str(5, $1, make_str("("), $3, make_str(")"), $5); }
3451 CharacterWithoutLength: character opt_charset
3452 { $$ = cat2_str($1, $2); }
3455 character: CHARACTER opt_varying
3456 { $$ = cat2_str(make_str("character"), $2); }
3457 | CHAR_P opt_varying
3458 { $$ = cat2_str(make_str("char"), $2); }
3460 { $$ = make_str("varchar"); }
3461 | NATIONAL CHARACTER opt_varying
3462 { $$ = cat2_str(make_str("national character"), $3); }
3463 | NATIONAL CHAR_P opt_varying
3464 { $$ = cat2_str(make_str("national char"), $3); }
3466 { $$ = cat2_str(make_str("nchar"), $2); }
3469 opt_varying: VARYING
3470 { $$ = make_str("varying"); }
3475 opt_charset: CHARACTER SET ColId
3476 { $$ = cat2_str(make_str("character set"), $3); }
3481 ConstDatetime: TIMESTAMP '(' PosIntConst ')' opt_timezone
3482 { $$ = cat_str(4, make_str("timestamp("), $3, make_str(")"), $5); }
3483 | TIMESTAMP opt_timezone
3484 { $$ = cat2_str(make_str("timestamp"), $2); }
3485 | TIME '(' PosIntConst ')' opt_timezone
3486 { $$ = cat_str(4, make_str("time("), $3, make_str(")"), $5); }
3488 { $$ = cat2_str(make_str("time"), $2); }
3491 ConstInterval: INTERVAL
3492 { $$ = make_str("interval"); }
3495 opt_timezone: WITH TIME ZONE
3496 { $$ = make_str("with time zone"); }
3498 { $$ = make_str("without time zone"); }
3503 opt_interval: YEAR_P { $$ = make_str("year"); }
3504 | MONTH_P { $$ = make_str("month"); }
3505 | DAY_P { $$ = make_str("day"); }
3506 | HOUR_P { $$ = make_str("hour"); }
3507 | MINUTE_P { $$ = make_str("minute"); }
3508 | SECOND_P { $$ = make_str("second"); }
3509 | YEAR_P TO MONTH_P { $$ = make_str("year to month"); }
3510 | DAY_P TO HOUR_P { $$ = make_str("day to hour"); }
3511 | DAY_P TO MINUTE_P { $$ = make_str("day to minute"); }
3512 | DAY_P TO SECOND_P { $$ = make_str("day to second"); }
3513 | HOUR_P TO MINUTE_P { $$ = make_str("hour to minute"); }
3514 | MINUTE_P TO SECOND_P { $$ = make_str("minute to second"); }
3515 | HOUR_P TO SECOND_P { $$ = make_str("hour to second"); }
3516 | /*EMPTY*/ { $$ = EMPTY; }
3520 /*****************************************************************************
3522 * expression grammar
3524 *****************************************************************************/
3526 /* General expressions
3527 * This is the heart of the expression syntax.
3529 * We have two expression types: a_expr is the unrestricted kind, and
3530 * b_expr is a subset that must be used in some places to avoid shift/reduce
3531 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
3532 * because that use of AND conflicts with AND as a boolean operator. So,
3533 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
3535 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
3536 * always be used by surrounding it with parens.
3538 * c_expr is all the productions that are common to a_expr and b_expr;
3539 * it's factored out just to eliminate redundant coding.
3544 | a_expr TYPECAST Typename
3545 { $$ = cat_str(3, $1, make_str("::"), $3); }
3546 | a_expr AT TIME ZONE c_expr
3547 { $$ = cat_str(3, $1, make_str("at time zone"), $5); }
3549 * These operators must be called out explicitly in order to make use
3550 * of yacc/bison's automatic operator-precedence handling. All other
3551 * operator names are handled by the generic productions using "Op",
3552 * below; and all those operators will have the same precedence.
3554 * If you add more explicitly-known operators, be sure to add them
3555 * also to b_expr and to the MathOp list above.
3557 | '+' a_expr %prec UMINUS
3558 { $$ = cat2_str(make_str("+"), $2); }
3559 | '-' a_expr %prec UMINUS
3560 { $$ = cat2_str(make_str("-"), $2); }
3562 { $$ = cat2_str(make_str("%"), $2); }
3564 { $$ = cat2_str(make_str("^"), $2); }
3566 { $$ = cat2_str($1, make_str("%")); }
3568 { $$ = cat2_str($1, make_str("^")); }
3570 { $$ = cat_str(3, $1, make_str("+"), $3); }
3572 { $$ = cat_str(3, $1, make_str("-"), $3); }
3574 { $$ = cat_str(3, $1, make_str("*"), $3); }
3576 { $$ = cat_str(3, $1, make_str("/"), $3); }
3578 { $$ = cat_str(3, $1, make_str("%"), $3); }
3580 { $$ = cat_str(3, $1, make_str("^"), $3); }
3582 { $$ = cat_str(3, $1, make_str("<"), $3); }
3584 { $$ = cat_str(3, $1, make_str(">"), $3); }
3586 { $$ = cat_str(3, $1, make_str("="), $3); }
3587 | a_expr qual_Op a_expr %prec Op
3588 { $$ = cat_str(3, $1, $2, $3); }
3589 | qual_Op a_expr %prec Op
3590 { $$ = cat2_str($1, $2); }
3591 | a_expr qual_Op %prec POSTFIXOP
3592 { $$ = cat2_str($1, $2); }
3594 { $$ = cat_str(3, $1, make_str("and"), $3); }
3596 { $$ = cat_str(3, $1, make_str("or"), $3); }
3598 { $$ = cat2_str(make_str("not"), $2); }
3599 | a_expr LIKE a_expr
3600 { $$ = cat_str(3, $1, make_str("like"), $3); }
3601 | a_expr LIKE a_expr ESCAPE a_expr
3602 { $$ = cat_str(5, $1, make_str("like"), $3, make_str("escape"), $5); }
3603 | a_expr NOT LIKE a_expr
3604 { $$ = cat_str(3, $1, make_str("not like"), $4); }
3605 | a_expr NOT LIKE a_expr ESCAPE a_expr
3606 { $$ = cat_str(5, $1, make_str("not like"), $4, make_str("escape"), $6); }
3607 | a_expr ILIKE a_expr
3608 { $$ = cat_str(3, $1, make_str("ilike"), $3); }
3609 | a_expr ILIKE a_expr ESCAPE a_expr
3610 { $$ = cat_str(5, $1, make_str("ilike"), $3, make_str("escape"), $5); }
3611 | a_expr NOT ILIKE a_expr
3612 { $$ = cat_str(3, $1, make_str("not ilike"), $4); }
3613 | a_expr NOT ILIKE a_expr ESCAPE a_expr
3614 { $$ = cat_str(5, $1, make_str("not ilike"), $4, make_str("escape"), $6); }
3615 | a_expr SIMILAR TO a_expr %prec SIMILAR
3616 { $$ = cat_str(3, $1, make_str("similar to"), $4); }
3617 | a_expr SIMILAR TO a_expr ESCAPE a_expr
3618 { $$ = cat_str(5, $1, make_str("similar to"), $4, make_str("escape"), $6); }
3619 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
3620 { $$ = cat_str(3, $1, make_str("not similar to"), $5); }
3621 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
3622 { $$ = cat_str(5, $1, make_str("not similar to"), $5, make_str("escape"), $7); }
3624 { $$ = cat2_str($1, make_str("isnull")); }
3626 { $$ = cat2_str($1, make_str("is null")); }
3628 { $$ = cat2_str($1, make_str("notnull")); }
3629 | a_expr IS NOT NULL_P
3630 { $$ = cat2_str($1, make_str("is not null")); }
3631 /* IS TRUE, IS FALSE, etc used to be function calls
3632 * but let's make them expressions to allow the optimizer
3633 * a chance to eliminate them if a_expr is a constant string.
3634 * - thomas 1997-12-22
3636 * Created BooleanTest Node type, and changed handling
3641 { $$ = cat2_str($1, make_str("is true")); }
3642 | a_expr IS NOT TRUE_P
3643 { $$ = cat2_str($1, make_str("is not true")); }
3645 { $$ = cat2_str($1, make_str("is false")); }
3646 | a_expr IS NOT FALSE_P
3647 { $$ = cat2_str($1, make_str("is not false")); }
3649 { $$ = cat2_str($1, make_str("is unknown")); }
3650 | a_expr IS NOT UNKNOWN
3651 { $$ = cat2_str($1, make_str("is not unknown")); }
3652 | a_expr IS DISTINCT FROM a_expr %prec IS
3653 { $$ = cat_str(3, $1, make_str("is distinct from"), $5); }
3654 | a_expr IS OF '(' type_list ')' %prec IS
3655 { $$ = cat_str(4, $1, make_str("is of ("), $5, make_str(")")); }
3656 | a_expr IS NOT OF '(' type_list ')' %prec IS
3657 { $$ = cat_str(4, $1, make_str("is not of ("), $6, make_str(")")); }
3658 | a_expr BETWEEN b_expr AND b_expr %prec BETWEEN
3659 { $$ = cat_str(5, $1, make_str("between"), $3, make_str("and"), $5); }
3660 | a_expr NOT BETWEEN b_expr AND b_expr %prec BETWEEN
3661 { $$ = cat_str(5, $1, make_str("not between"), $4, make_str("and"), $6); }
3662 | a_expr IN_P in_expr
3663 { $$ = cat_str(3, $1, make_str("in"), $3); }
3664 | a_expr NOT IN_P in_expr
3665 { $$ = cat_str(3, $1, make_str("not in"), $4); }
3666 | a_expr subquery_Op sub_type select_with_parens %prec Op
3667 { $$ = cat_str(4, $1, $2, $3, $4); }
3668 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
3669 { $$ = cat_str(6, $1, $2, $3, make_str("("), $5, make_str(")")); }
3670 | UNIQUE select_with_parens %prec Op
3671 { $$ = cat2_str(make_str("unique"), $2); }
3674 /* Restricted expressions
3676 * b_expr is a subset of the complete expression syntax
3678 * Presently, AND, NOT, IS and IN are the a_expr keywords that would
3679 * cause trouble in the places where b_expr is used. For simplicity, we
3680 * just eliminate all the boolean-keyword-operator productions from b_expr.
3684 | b_expr TYPECAST Typename
3685 { $$ = cat_str(3, $1, make_str("::"), $3); }
3686 | '-' b_expr %prec UMINUS
3687 { $$ = cat2_str(make_str("-"), $2); }
3689 { $$ = cat2_str(make_str("%"), $2); }
3691 { $$ = cat2_str(make_str("^"), $2); }
3693 { $$ = cat2_str($1, make_str("%")); }
3695 { $$ = cat2_str($1, make_str("^")); }
3697 { $$ = cat_str(3, $1, make_str("+"), $3); }
3699 { $$ = cat_str(3, $1, make_str("-"), $3); }
3701 { $$ = cat_str(3, $1, make_str("*"), $3); }
3703 { $$ = cat_str(3, $1, make_str("/"), $3); }
3705 { $$ = cat_str(3, $1, make_str("%"), $3); }
3707 { $$ = cat_str(3, $1, make_str("^"), $3); }
3709 { $$ = cat_str(3, $1, make_str("<"), $3); }
3711 { $$ = cat_str(3, $1, make_str(">"), $3); }
3713 { $$ = cat_str(3, $1, make_str("="), $3); }
3715 { $$ = cat_str(3, $1, $2, $3); }
3716 | qual_Op b_expr %prec Op
3717 { $$ = cat2_str($1, $2); }
3718 | b_expr qual_Op %prec POSTFIXOP
3719 { $$ = cat2_str($1, $2); }
3720 | b_expr IS DISTINCT FROM b_expr %prec IS
3721 { $$ = cat_str(3, $1, make_str("is distinct from"), $5); }
3722 | b_expr IS OF '(' b_expr ')' %prec IS
3723 { $$ = cat_str(4, $1, make_str("is of ("), $5, make_str(")")); }
3724 | b_expr IS NOT OF '(' b_expr ')' %prec IS
3725 { $$ = cat_str(4, $1, make_str("is not of ("), $6, make_str(")")); }
3729 * Productions that can be used in both a_expr and b_expr.
3731 * Note: productions that refer recursively to a_expr or b_expr mostly
3732 * cannot appear here. However, it's OK to refer to a_exprs that occur
3733 * inside parentheses, such as function arguments; that cannot introduce
3734 * ambiguity to the b_expr syntax.
3740 | PARAM opt_indirection
3741 { $$ = cat2_str(make_str("param"), $2); }
3742 | '(' a_expr ')' opt_indirection
3743 { $$ = cat_str(4, make_str("("), $2, make_str(")"), $4); }
3747 { $$ = cat2_str($1, make_str("()")); }
3748 | func_name '(' expr_list ')'
3749 { $$ = cat_str(4, $1, make_str("("), $3, make_str(")")); }
3750 | func_name '(' ALL expr_list ')'
3751 { $$ = cat_str(4, $1, make_str("( all"), $4, make_str(")")); }
3752 | func_name '(' DISTINCT expr_list ')'
3753 { $$ = cat_str(4, $1, make_str("( distinct"), $4, make_str(")")); }
3754 | func_name '(' '*' ')'
3755 { $$ = cat2_str($1, make_str("(*)")); }
3757 { $$ = make_str("current_date"); }
3758 | CURRENT_TIME opt_empty_parentheses
3759 { $$ = cat2_str(make_str("current_time"), $2); }
3760 | CURRENT_TIME '(' PosIntConst ')'
3761 { $$ = make_str("current_time"); }
3762 | CURRENT_TIMESTAMP opt_empty_parentheses
3763 { $$ = cat2_str(make_str("current_timestamp"), $2); }
3764 | CURRENT_TIMESTAMP '(' PosIntConst ')'
3765 { $$ = make_str("current_timestamp"); }
3766 | CURRENT_USER opt_empty_parentheses
3767 { $$ = cat2_str(make_str("current_user"), $2); }
3768 | SESSION_USER opt_empty_parentheses
3769 { $$ = cat2_str(make_str("session_user"), $2); }
3770 | USER opt_empty_parentheses
3771 { $$ = cat2_str(make_str("user"), $2); }
3772 | CAST '(' a_expr AS Typename ')'
3773 { $$ = cat_str(5, make_str("cast("), $3, make_str("as"), $5, make_str(")")); }
3774 | EXTRACT '(' extract_list ')'
3775 { $$ = cat_str(3, make_str("extract("), $3, make_str(")")); }
3776 | OVERLAY '(' overlay_list ')'
3777 { $$ = cat_str(3, make_str("overlay("), $3, make_str(")")); }
3778 | POSITION '(' position_list ')'
3779 { $$ = cat_str(3, make_str("position("), $3, make_str(")")); }
3780 | SUBSTRING '(' substr_list ')'
3781 { $$ = cat_str(3, make_str("substring("), $3, make_str(")")); }
3782 | TREAT '(' a_expr AS Typename ')'
3783 { $$ = cat_str(5, make_str("treat("), $3, make_str("as"), $5, make_str(")")); }
3784 /* various trim expressions are defined in SQL92 - thomas 1997-07-19 */
3785 | TRIM '(' BOTH trim_list ')'
3786 { $$ = cat_str(3, make_str("trim(both"), $4, make_str(")")); }
3787 | TRIM '(' LEADING trim_list ')'
3788 { $$ = cat_str(3, make_str("trim(leading"), $4, make_str(")")); }
3789 | TRIM '(' TRAILING trim_list ')'
3790 { $$ = cat_str(3, make_str("trim(trailing"), $4, make_str(")")); }
3791 | TRIM '(' trim_list ')'
3792 { $$ = cat_str(3, make_str("trim("), $3, make_str(")")); }
3793 | CONVERT '(' a_expr USING any_name ')'
3794 { $$ = cat_str(5, make_str("convert("), $3, make_str("using"), $5, make_str(")"));}
3795 | CONVERT '(' expr_list ')'
3796 { $$ = cat_str(3, make_str("convert("), $3, make_str(")")); }
3797 | select_with_parens %prec UMINUS
3799 | EXISTS select_with_parens
3800 { $$ = cat2_str(make_str("exists"), $2); }
3801 | ARRAY select_with_parens
3802 { $$ = cat2_str(make_str("array"), $2); }
3804 { $$ = cat2_str(make_str("array"), $2); }
3809 row: ROW '(' expr_list ')'
3810 { $$ = cat_str(3, make_str("row ("), $3, make_str(")")); }
3812 { $$ = make_str("row()"); }
3813 | '(' expr_list ',' a_expr ')'
3814 { $$ = cat_str(5, make_str("("), $2, make_str(","), $4, make_str(")")); }
3817 sub_type: ANY { $$ = make_str("ANY"); }
3818 | SOME { $$ = make_str("SOME"); }
3819 | ALL { $$ = make_str("ALL"); }
3822 all_Op: Op { $$ = $1; }
3823 | MathOp { $$ = $1; }
3826 MathOp: '+' { $$ = make_str("+"); }
3827 | '-' { $$ = make_str("-"); }
3828 | '*' { $$ = make_str("*"); }
3829 | '%' { $$ = make_str("%"); }
3830 | '^' { $$ = make_str("^"); }
3831 | '/' { $$ = make_str("/"); }
3832 | '<' { $$ = make_str("<"); }
3833 | '>' { $$ = make_str(">"); }
3834 | '=' { $$ = make_str("="); }
3837 qual_Op: Op { $$ = $1; }
3838 | OPERATOR '(' any_operator ')' { $$ = cat_str(3, make_str("operator ("), $3, make_str(")")); }
3841 qual_all_Op: all_Op { $$ = $1; }
3842 | OPERATOR '(' any_operator ')' { $$ = cat_str(3, make_str("operator ("), $3, make_str(")")); }
3845 subquery_Op: all_Op { $$ = $1; }
3846 | OPERATOR '(' any_operator ')' { $$ = cat_str(3, make_str("operator ("), $3, make_str(")")); }
3847 | LIKE { $$ = make_str("like"); }
3848 | NOT LIKE { $$ = make_str("not like"); }
3849 | ILIKE { $$ = make_str("ilike"); }
3850 | NOT ILIKE { $$ = make_str("not ilike"); }
3855 | expr_list ',' a_expr
3856 { $$ = cat_str(3, $1, make_str(","), $3); }
3859 extract_list: extract_arg FROM a_expr
3860 { $$ = cat_str(3, $1, make_str("from"), $3); }
3865 type_list: type_list ',' Typename
3866 { $$ = cat_str(3, $1, ',', $3); }
3871 array_expr_list: array_expr { $$ = $1; }
3872 | array_expr_list ',' array_expr { $$ = cat_str(3, $1, make_str(","), $3); }
3876 array_expr: '[' expr_list ']' { $$ = cat_str(3, make_str("["), $2, make_str("]")); }
3877 | '[' array_expr_list ']' { $$ = cat_str(3, make_str("["), $2, make_str("]")); }
3879 /* Allow delimited string SCONST in extract_arg as an SQL extension.
3880 * - thomas 2001-04-12
3883 extract_arg: ident { $$ = $1; }
3884 | YEAR_P { $$ = make_str("year"); }
3885 | MONTH_P { $$ = make_str("month"); }
3886 | DAY_P { $$ = make_str("day"); }
3887 | HOUR_P { $$ = make_str("hour"); }
3888 | MINUTE_P { $$ = make_str("minute"); }
3889 | SECOND_P { $$ = make_str("second"); }
3890 | StringConst { $$ = $1; }
3894 a_expr overlay_placing substr_from substr_for
3895 { $$ = cat_str(4, $1, 42, $3, $4); }
3896 | a_expr overlay_placing substr_from
3897 { $$ = cat_str(3, $1, $2, $3); }
3901 PLACING a_expr { $$ = cat2_str(make_str("placing"), $2); }
3904 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
3905 position_list: b_expr IN_P b_expr
3906 { $$ = cat_str(3, $1, make_str("in"), $3); }
3911 substr_list: a_expr substr_from substr_for
3912 { $$ = cat_str(3, $1, $2, $3); }
3913 | a_expr substr_for substr_from
3914 { $$ = cat_str(3, $1, $2, $3); }
3915 | a_expr substr_from
3916 { $$ = cat2_str($1, $2); }
3918 { $$ = cat2_str($1, $2); }
3925 substr_from: FROM a_expr
3926 { $$ = cat2_str(make_str("from"), $2); }
3929 substr_for: FOR a_expr
3930 { $$ = cat2_str(make_str("for"), $2); }
3933 trim_list: a_expr FROM expr_list
3934 { $$ = cat_str(3, $1, make_str("from"), $3); }
3936 { $$ = cat2_str(make_str("from"), $2); }
3941 in_expr: select_with_parens
3944 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
3948 * Define SQL92-style case clause.
3949 * Allow all four forms described in the standard:
3950 * - Full specification
3951 * CASE WHEN a = b THEN c ... ELSE d END
3952 * - Implicit argument
3953 * CASE a WHEN b THEN c ... ELSE d END
3954 * - Conditional NULL
3956 * same as CASE WHEN x = y THEN NULL ELSE x END
3957 * - Conditional substitution from list, use first non-null argument
3959 * same as CASE WHEN a IS NOT NULL THEN a WHEN b IS NOT NULL THEN b ... END
3960 * - thomas 1998-11-09
3962 case_expr: CASE case_arg when_clause_list case_default END_P
3963 { $$ = cat_str(5, make_str("case"), $2, $3, $4, make_str("end")); }
3964 | NULLIF '(' a_expr ',' a_expr ')'
3965 { $$ = cat_str(5, make_str("nullif("), $3, make_str(","), $5, make_str(")")); }
3966 | COALESCE '(' expr_list ')'
3967 { $$ = cat_str(3, make_str("coalesce("), $3, make_str(")")); }
3970 when_clause_list: when_clause_list when_clause
3971 { $$ = cat2_str($1, $2); }
3976 when_clause: WHEN a_expr THEN a_expr
3977 { $$ = cat_str(4, make_str("when"), $2, make_str("then"), $4); }
3980 case_default: ELSE a_expr
3981 { $$ = cat2_str(make_str("else"), $2); }
3986 case_arg: a_expr { $$ = $1; }
3987 | /*EMPTY*/ { $$ = EMPTY; }
3990 columnref: relation_name { $$ = $1; }
3991 | relation_name indirection { $$ = cat2_str($1, $2); }
3995 '.' attr_name { $$ = cat2_str(make_str("."), $2); }
3996 | '.' '*' { $$ = make_str(".*"); }
3997 | '[' a_expr ']' { $$ = cat_str(3, make_str("["), $2, make_str("]")); }
3998 | '[' a_expr ':' a_expr ']' { $$ = cat_str(5, make_str("["), $2, make_str(":"), $4, make_str("]")); }
4001 indirection: indirection_el { $$ = $1; }
4002 | indirection indirection_el { $$ = cat2_str($1, $2); }
4006 /*EMPTY*/ { $$ = EMPTY; }
4007 | opt_indirection indirection_el { $$ = cat2_str($1, $2);}
4010 opt_empty_parentheses: '(' ')' { $$ = make_str("()"); }
4011 | /*EMPTY*/ { $$ = EMPTY; }
4015 /*****************************************************************************
4017 * target lists for SELECT, UPDATE, INSERT
4019 *****************************************************************************/
4021 target_list: target_list ',' target_el
4022 { $$ = cat_str(3, $1, make_str(","), $3); }
4027 /* AS is not optional because shift/red conflict with unary ops */
4028 target_el: a_expr AS ColLabel
4029 { $$ = cat_str(3, $1, make_str("as"), $3); }
4033 { $$ = make_str("*"); }
4036 /* Target list as found in UPDATE table SET ... */
4037 update_target_list: update_target_list ',' update_target_el
4038 { $$ = cat_str(3, $1, make_str(","),$3); }
4039 | '(' inf_col_list ')' '=' '(' inf_val_list ')'
4041 struct inf_compat_col *ptrc;
4042 struct inf_compat_val *ptrv;
4043 char *cols = make_str( "(" );
4044 char *vals = make_str( "(" );
4046 for (ptrc = informix_col, ptrv = informix_val; ptrc != NULL && ptrv != NULL; ptrc = ptrc->next, ptrv = ptrv->next)
4048 if ( ptrc->next != NULL )
4050 cols = cat_str(4, cols, ptrc->name, ptrc->indirection, make_str(",") );
4054 cols = cat_str(4, cols, ptrc->name, ptrc->indirection, make_str(")") );
4056 if (ptrv->next != NULL )
4057 vals = cat_str(3, vals, ptrv->val, make_str("," ) );
4059 vals = cat_str( 3, vals, ptrv->val, make_str(")") );
4061 $$ = cat_str( 3, cols, make_str("="), vals );
4067 inf_col_list: ColId opt_indirection
4069 struct inf_compat_col *ptr = mm_alloc(sizeof(struct inf_compat_col));
4072 ptr->indirection = $2;
4076 | ColId opt_indirection ',' inf_col_list
4078 struct inf_compat_col *ptr = mm_alloc(sizeof(struct inf_compat_col));
4081 ptr->indirection = $2;
4082 ptr->next = informix_col;
4087 inf_val_list: a_expr
4089 struct inf_compat_val *ptr = mm_alloc(sizeof(struct inf_compat_val));
4095 | a_expr ',' inf_val_list
4097 struct inf_compat_val *ptr = mm_alloc(sizeof(struct inf_compat_val));
4100 ptr->next = informix_val;
4105 update_target_el: ColId opt_indirection '=' a_expr
4106 { $$ = cat_str(4, $1, $2, make_str("="), $4); }
4107 | ColId opt_indirection '=' DEFAULT
4108 { $$ = cat_str(3, $1, $2, make_str("= default")); }
4111 insert_target_list: insert_target_list ',' insert_target_el
4112 { $$ = cat_str(3, $1, make_str(","), $3); }
4117 insert_target_el: a_expr { $$ = $1; }
4118 | DEFAULT { $$ = make_str("default"); }
4122 /*****************************************************************************
4124 * Names and constants
4126 *****************************************************************************/
4128 relation_name: SpecialRuleRelation { $$ = $1; }
4129 | ColId { $$ = $1; }
4132 qualified_name_list: qualified_name
4134 | qualified_name_list ',' qualified_name
4135 { $$ = cat_str(3, $1, make_str(","), $3); }
4138 qualified_name: relation_name
4140 | relation_name attrs
4141 { $$ = cat2_str($1, $2); }
4146 | name_list ',' name
4147 { $$ = cat_str(3, $1, make_str(","), $3); }
4151 name: ColId { $$ = $1; };
4152 database_name: ColId { $$ = $1; };
4153 access_method: ColId { $$ = $1; };
4154 attr_name: ColId { $$ = $1; };
4155 index_name: ColId { $$ = $1; };
4157 file_name: StringConst { $$ = $1; };
4159 func_name: function_name
4161 | relation_name indirection
4162 { $$ = cat2_str($1, $2); }
4167 * Include TRUE/FALSE for SQL3 support. - thomas 1997-10-24
4169 AexprConst: PosAllConst
4171 | ConstTypename StringConst
4172 { $$ = cat2_str($1, $2); }
4173 | ConstInterval StringConst opt_interval
4174 { $$ = cat_str(3, $1, $2, $3); }
4175 | ConstInterval '(' PosIntConst ')' StringConst opt_interval
4176 { $$ = cat_str(6, $1, make_str("("), $3, make_str(")"), $5, $6); }
4178 { $$ = make_str("true"); }
4180 { $$ = make_str("false"); }
4182 { $$ = make_str("null"); }
4187 Iconst: ICONST { $$ = make_name();};
4188 Fconst: FCONST { $$ = make_name();};
4189 Bconst: BCONST { $$ = make_name();};
4190 Xconst: XCONST { $$ = make_name();};
4193 $$ = (char *)mm_alloc(strlen($1) + 3);
4196 $$[strlen($1)+2]='\0';
4197 $$[strlen($1)+1]='\'';
4202 PosIntConst: Iconst { $$ = $1; }
4203 | civar { $$ = $1; }
4206 IntConst: PosIntConst { $$ = $1; }
4207 | '-' PosIntConst { $$ = cat2_str(make_str("-"), $2); }
4212 char *length = mm_alloc(32);
4214 sprintf(length, "%d", (int) strlen($1));
4215 new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0);
4218 | cvariable { $$ = $1; }
4223 char *length = mm_alloc(32);
4225 sprintf(length, "%d", (int) strlen($1));
4226 new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0);
4229 | IntConstVar { $$ = $1; }
4232 char *length = mm_alloc(32);
4233 char *var = cat2_str(make_str("-"), $2);
4235 sprintf(length, "%d", (int) strlen(var));
4236 new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
4241 char *length = mm_alloc(32);
4242 char *var = cat2_str(make_str("-"), $2);
4244 sprintf(length, "%d", (int) strlen(var));
4245 new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
4250 char *length = mm_alloc(32);
4253 var[strlen(var) - 1] = '\0';
4254 sprintf(length, "%d", (int) strlen(var));
4255 new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
4260 StringConst: Sconst { $$ = $1; }
4261 | civar { $$ = $1; }
4264 PosIntStringConst: Iconst { $$ = $1; }
4265 | Sconst { $$ = $1; }
4266 | civar { $$ = $1; }
4269 NumConst: Fconst { $$ = $1; }
4270 | Iconst { $$ = $1; }
4271 | '-' Fconst { $$ = cat2_str(make_str("-"), $2); }
4272 | '-' Iconst { $$ = cat2_str(make_str("-"), $2); }
4273 | civar { $$ = $1; }
4276 AllConst: Sconst { $$ = $1; }
4277 | NumConst { $$ = $1; }
4280 PosAllConst: Sconst { $$ = $1; }
4281 | Fconst { $$ = $1; }
4282 | Iconst { $$ = $1; }
4283 | Bconst { $$ = $1; }
4284 | Xconst { $$ = $1; }
4285 | civar { $$ = $1; }
4288 UserId: ColId { $$ = $1;};
4290 SpecialRuleRelation: OLD
4293 mmerror(PARSE_ERROR, ET_ERROR, "OLD used in non-rule query");
4295 $$ = make_str("old");
4300 mmerror(PARSE_ERROR, ET_ERROR, "NEW used in non-rule query");
4302 $$ = make_str("new");
4307 * and now special embedded SQL stuff
4311 * the exec sql connect statement: connect to the given database
4313 ECPGConnect: SQL_CONNECT TO connection_target opt_connection_name opt_user
4314 { $$ = cat_str(5, $3, make_str(","), $5, make_str(","), $4); }
4315 | SQL_CONNECT TO DEFAULT
4316 { $$ = make_str("NULL,NULL,NULL,\"DEFAULT\""); }
4317 /* also allow ORACLE syntax */
4318 | SQL_CONNECT ora_user
4319 { $$ = cat_str(3, make_str("NULL,"), $2, make_str(",NULL")); }
4320 | DATABASE connection_target
4321 { $$ = cat2_str($2, make_str(",NULL,NULL,NULL")); }
4324 connection_target: database_name opt_server opt_port
4326 /* old style: dbname[@server][:port] */
4327 if (strlen($2) > 0 && *($2) != '@')
4328 mmerror(PARSE_ERROR, ET_ERROR, "Expected '@', found '%s'", $2);
4330 $$ = make3_str(make_str("\""), make3_str($1, $2, $3), make_str("\""));
4332 | db_prefix ':' server opt_port '/' database_name opt_options
4334 /* new style: <tcp|unix>:postgresql://server[:port][/dbname] */
4335 if (strncmp($1, "unix:postgresql", strlen("unix:postgresql")) != 0 && strncmp($1, "tcp:postgresql", strlen("tcp:postgresql")) != 0)
4336 mmerror(PARSE_ERROR, ET_ERROR, "only protocols 'tcp' and 'unix' and database type 'postgresql' are supported");
4338 if (strncmp($3, "//", strlen("//")) != 0)
4339 mmerror(PARSE_ERROR, ET_ERROR, "Expected '://', found '%s'", $3);
4341 if (strncmp($1, "unix", strlen("unix")) == 0 &&
4342 strncmp($3 + strlen("//"), "localhost", strlen("localhost")) != 0 &&
4343 strncmp($3 + strlen("//"), "127.0.0.1", strlen("127.0.0.1")) != 0)
4344 mmerror(PARSE_ERROR, ET_ERROR, "unix domain sockets only work on 'localhost' but not on '%9.9s'", $3 + strlen("//"));
4346 $$ = make3_str(make3_str(make_str("\""), $1, make_str(":")), $3, make3_str(make3_str($4, make_str("/"), $6), $7, make_str("\"")));
4353 $$ = make3_str(make_str("\""), $1, make_str("\""));
4361 db_prefix: ident cvariable
4363 if (strcmp($2, "postgresql") != 0 && strcmp($2, "postgres") != 0)
4364 mmerror(PARSE_ERROR, ET_ERROR, "Expected 'postgresql', found '%s'", $2);
4366 if (strcmp($1, "tcp") != 0 && strcmp($1, "unix") != 0)
4367 mmerror(PARSE_ERROR, ET_ERROR, "Illegal connection type %s", $1);
4369 $$ = make3_str($1, make_str(":"), $2);
4373 server: Op server_name
4375 if (strcmp($1, "@") != 0 && strcmp($1, "//") != 0)
4376 mmerror(PARSE_ERROR, ET_ERROR, "Expected '@' or '://', found '%s'", $1);
4378 $$ = make2_str($1, $2);
4382 opt_server: server { $$ = $1; }
4383 | /*EMPTY*/ { $$ = EMPTY; }
4386 server_name: ColId { $$ = $1; }
4387 | ColId '.' server_name { $$ = make3_str($1, make_str("."), $3); }
4388 | IP { $$ = make_name(); }
4391 opt_port: ':' PosIntConst { $$ = make2_str(make_str(":"), $2); }
4392 | /*EMPTY*/ { $$ = EMPTY; }
4395 opt_connection_name: AS connection_target { $$ = $2; }
4396 | /*EMPTY*/ { $$ = make_str("NULL"); }
4399 opt_user: USER ora_user { $$ = $2; }
4400 | /*EMPTY*/ { $$ = make_str("NULL,NULL"); }
4404 { $$ = cat2_str($1, make_str(", NULL")); }
4405 | user_name '/' user_name
4406 { $$ = cat_str(3, $1, make_str(","), $3); }
4407 | user_name SQL_IDENTIFIED BY user_name
4408 { $$ = cat_str(3, $1, make_str(","), $4); }
4409 | user_name USING user_name
4410 { $$ = cat_str(3, $1, make_str(","), $3); }
4418 $$ = make3_str(make_str("\""), $1, make_str("\""));
4424 else if (strcmp($1, " ?") == 0) /* variable */
4426 enum ECPGttype type = argsinsert->variable->type->type;
4428 /* if array see what's inside */
4429 if (type == ECPGt_array)
4430 type = argsinsert->variable->type->u.element->type;
4432 /* handle varchars */
4433 if (type == ECPGt_varchar)
4434 $$ = make2_str(mm_strdup(argsinsert->variable->name), make_str(".arr"));
4436 $$ = mm_strdup(argsinsert->variable->name);
4439 $$ = make3_str(make_str("\""), $1, make_str("\""));
4443 char_variable: cvariable
4445 /* check if we have a string variable */
4446 struct variable *p = find_variable($1);
4447 enum ECPGttype type = p->type->type;
4449 /* If we have just one character this is not a string */
4450 if (atol(p->type->size) == 1)
4451 mmerror(PARSE_ERROR, ET_ERROR, "invalid datatype");
4454 /* if array see what's inside */
4455 if (type == ECPGt_array)
4456 type = p->type->u.element->type;
4461 case ECPGt_unsigned_char:
4465 $$ = make2_str($1, make_str(".arr"));
4468 mmerror(PARSE_ERROR, ET_ERROR, "invalid datatype");
4475 opt_options: Op ColId
4477 if (strlen($1) == 0)
4478 mmerror(PARSE_ERROR, ET_ERROR, "incomplete statement");
4480 if (strcmp($1, "?") != 0)
4481 mmerror(PARSE_ERROR, ET_ERROR, "unrecognised token '%s'", $1);
4483 $$ = make2_str(make_str("?"), $2);
4485 | /*EMPTY*/ { $$ = EMPTY; }
4489 * Declare a prepared cursor. The syntax is different from the standard
4490 * declare statement, so we create a new rule.
4492 ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
4494 struct cursor *ptr, *this;
4495 struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
4497 for (ptr = cur; ptr != NULL; ptr = ptr->next)
4499 if (strcmp($2, ptr->name) == 0)
4500 /* re-definition is a bug */
4501 mmerror(PARSE_ERROR, ET_ERROR, "cursor %s already defined", $2);
4504 this = (struct cursor *) mm_alloc(sizeof(struct cursor));
4506 /* initial definition */
4509 this->connection = connection;
4510 this->command = cat_str(6, make_str("declare"), mm_strdup($2), $3, make_str("cursor"), $5, make_str("for ?"));
4511 this->argsresult = NULL;
4513 thisquery->type = &ecpg_query;
4514 thisquery->brace_level = 0;
4515 thisquery->next = NULL;
4516 thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement()") + strlen($7));
4517 sprintf(thisquery->name, "ECPGprepared_statement(%s)", $7);
4519 this->argsinsert = NULL;
4520 add_variable_to_head(&(this->argsinsert), thisquery, &no_indicator);
4524 $$ = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
4529 * the exec sql deallocate prepare command to deallocate a previously
4530 * prepared statement
4532 ECPGDeallocate: DEALLOCATE PREPARE prepared_name
4534 | DEALLOCATE prepared_name
4539 * variable decalartion outside exec sql declare block
4541 ECPGVarDeclaration: single_vt_declaration;
4543 single_vt_declaration: type_declaration { $$ = $1; }
4544 | single_var_declaration { $$ = $1; }
4547 single_var_declaration: storage_declaration
4550 actual_type[struct_level].type_enum = $2.type_enum;
4551 actual_type[struct_level].type_dimension = $2.type_dimension;
4552 actual_type[struct_level].type_index = $2.type_index;
4553 actual_type[struct_level].type_sizeof = $2.type_sizeof;
4555 actual_startline[struct_level] = hashline_number();
4559 $$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n"));
4563 actual_type[struct_level].type_enum = $1.type_enum;
4564 actual_type[struct_level].type_dimension = $1.type_dimension;
4565 actual_type[struct_level].type_index = $1.type_index;
4566 actual_type[struct_level].type_sizeof = $1.type_sizeof;
4568 actual_startline[struct_level] = hashline_number();
4572 $$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n"));
4574 | struct_union_type_with_symbol ';'
4576 $$ = cat2_str($1, make_str(";"));
4580 precision: NumConst { $$ = $1; };
4582 opt_scale: ',' NumConst { $$ = $2; }
4583 | /* EMPTY */ { $$ = EMPTY; }
4586 ecpg_interval: opt_interval { $$ = $1; }
4587 | YEAR_P TO MINUTE_P { $$ = make_str("year to minute"); }
4588 | YEAR_P TO SECOND_P { $$ = make_str("year to second"); }
4589 | DAY_P TO DAY_P { $$ = make_str("day to day"); }
4590 | MONTH_P TO MONTH_P { $$ = make_str("month to month"); }
4594 * variable declaration inside exec sql declare block
4596 ECPGDeclaration: sql_startdeclare
4597 { fputs("/* exec sql begin declare section */", yyout); }
4598 var_type_declarations sql_enddeclare
4600 fprintf(yyout, "%s/* exec sql end declare section */", $3);
4602 output_line_number();
4606 sql_startdeclare: ecpgstart BEGIN_P DECLARE SQL_SECTION ';' {};
4608 sql_enddeclare: ecpgstart END_P DECLARE SQL_SECTION ';' {};
4610 var_type_declarations: /*EMPTY*/ { $$ = EMPTY; }
4611 | vt_declarations { $$ = $1; }
4614 vt_declarations: var_declaration { $$ = $1; }
4615 | type_declaration { $$ = $1; }
4616 | vt_declarations var_declaration { $$ = cat2_str($1, $2); }
4617 | vt_declarations type_declaration { $$ = cat2_str($1, $2); }
4620 variable_declarations: var_declaration { $$ = $1; }
4621 | variable_declarations var_declaration { $$ = cat2_str($1, $2); }
4624 type_declaration: S_TYPEDEF
4626 /* reset this variable so we see if there was */
4627 /* an initializer specified */
4630 var_type opt_pointer ECPGColLabelCommon opt_array_bounds ';'
4632 /* add entry to list */
4633 struct typedefs *ptr, *this;
4634 char * dimension = $6.index1;
4635 char * length = $6.index2;
4637 if (($3.type_enum == ECPGt_struct ||
4638 $3.type_enum == ECPGt_union) &&
4641 mmerror(PARSE_ERROR, ET_ERROR, "Initializer not allowed in typedef command");
4646 for (ptr = types; ptr != NULL; ptr = ptr->next)
4648 if (strcmp($5, ptr->name) == 0)
4649 /* re-definition is a bug */
4650 mmerror(PARSE_ERROR, ET_ERROR, "Type %s already defined", $5);
4652 adjust_array($3.type_enum, &dimension, &length, $3.type_dimension, $3.type_index, *$4?1:0, true);
4654 this = (struct typedefs *) mm_alloc(sizeof(struct typedefs));
4656 /* initial definition */
4659 this->brace_level = braces_open;
4660 this->type = (struct this_type *) mm_alloc(sizeof(struct this_type));
4661 this->type->type_enum = $3.type_enum;
4662 this->type->type_str = mm_strdup($5);
4663 this->type->type_dimension = dimension; /* dimension of array */
4664 this->type->type_index = length; /* length of string */
4665 this->type->type_sizeof = ECPGstruct_sizeof;
4666 this->struct_member_list = ($3.type_enum == ECPGt_struct || $3.type_enum == ECPGt_union) ?
4667 struct_member_list[struct_level] : NULL;
4669 if ($3.type_enum != ECPGt_varchar &&
4670 $3.type_enum != ECPGt_char &&
4671 $3.type_enum != ECPGt_unsigned_char &&
4672 atoi(this->type->type_index) >= 0)
4673 mmerror(PARSE_ERROR, ET_ERROR, "No multidimensional array support for simple data types");
4678 fprintf(yyout, "typedef %s %s %s %s;\n", $3.type_str, *$4?"*":"", $5, $6.str);
4679 output_line_number();
4683 var_declaration: storage_declaration
4686 actual_type[struct_level].type_enum = $2.type_enum;
4687 actual_type[struct_level].type_dimension = $2.type_dimension;
4688 actual_type[struct_level].type_index = $2.type_index;
4689 actual_type[struct_level].type_sizeof = $2.type_sizeof;
4691 actual_startline[struct_level] = hashline_number();
4695 $$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n"));
4699 actual_type[struct_level].type_enum = $1.type_enum;
4700 actual_type[struct_level].type_dimension = $1.type_dimension;
4701 actual_type[struct_level].type_index = $1.type_index;
4702 actual_type[struct_level].type_sizeof = $1.type_sizeof;
4704 actual_startline[struct_level] = hashline_number();
4708 $$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n"));
4710 | struct_union_type_with_symbol ';'
4712 $$ = cat2_str($1, make_str(";"));
4716 storage_declaration: storage_clause storage_modifier
4718 $$ = cat2_str ($1, $2);
4730 storage_clause : S_EXTERN { $$ = make_str("extern"); }
4731 | S_STATIC { $$ = make_str("static"); }
4732 | S_REGISTER { $$ = make_str("register"); }
4733 | S_AUTO { $$ = make_str("auto"); }
4736 storage_modifier : S_CONST { $$ = make_str("const"); }
4737 | S_VOLATILE { $$ = make_str("volatile"); }
4740 var_type: simple_type
4743 $$.type_str = mm_strdup(ECPGtype_name($1));
4744 $$.type_dimension = make_str("-1");
4745 $$.type_index = make_str("-1");
4746 $$.type_sizeof = NULL;
4751 $$.type_dimension = make_str("-1");
4752 $$.type_index = make_str("-1");
4754 if (strncmp($1, "struct", sizeof("struct")-1) == 0)
4756 $$.type_enum = ECPGt_struct;
4757 $$.type_sizeof = ECPGstruct_sizeof;
4761 $$.type_enum = ECPGt_union;
4762 $$.type_sizeof = NULL;
4768 $$.type_enum = ECPGt_int;
4769 $$.type_dimension = make_str("-1");
4770 $$.type_index = make_str("-1");
4771 $$.type_sizeof = NULL;
4773 | ECPGColLabelCommon '(' precision opt_scale ')'
4775 if (strcmp($1, "numeric") == 0)
4777 $$.type_enum = ECPGt_numeric;
4778 $$.type_str = make_str("numeric");
4780 else if (strcmp($1, "decimal") == 0)
4782 $$.type_enum = ECPGt_decimal;
4783 $$.type_str = make_str("decimal");
4787 mmerror(PARSE_ERROR, ET_ERROR, "Only numeric/decimal have precision/scale argument");
4788 $$.type_enum = ECPGt_numeric;
4789 $$.type_str = make_str("numeric");
4792 $$.type_dimension = make_str("-1");
4793 $$.type_index = make_str("-1");
4794 $$.type_sizeof = NULL;
4796 | ECPGColLabelCommon ecpg_interval
4798 if (strlen($2) != 0 && strcmp ($1, "datetime") != 0 && strcmp ($1, "interval") != 0)
4799 mmerror (PARSE_ERROR, ET_ERROR, "Interval specification not allowed here ");
4802 * Check for type names that the SQL grammar treats as
4803 * unreserved keywords
4805 if (strcmp($1, "varchar") == 0)
4807 $$.type_enum = ECPGt_varchar;
4808 $$.type_str = EMPTY; /*make_str("varchar");*/
4809 $$.type_dimension = make_str("-1");
4810 $$.type_index = make_str("-1");
4811 $$.type_sizeof = NULL;
4813 else if (strcmp($1, "float") == 0)
4815 $$.type_enum = ECPGt_float;
4816 $$.type_str = make_str("float");
4817 $$.type_dimension = make_str("-1");
4818 $$.type_index = make_str("-1");
4819 $$.type_sizeof = NULL;
4821 else if (strcmp($1, "double") == 0)
4823 $$.type_enum = ECPGt_double;
4824 $$.type_str = make_str("double");
4825 $$.type_dimension = make_str("-1");
4826 $$.type_index = make_str("-1");
4827 $$.type_sizeof = NULL;
4829 else if (strcmp($1, "numeric") == 0)
4831 $$.type_enum = ECPGt_numeric;
4832 $$.type_str = make_str("numeric");
4833 $$.type_dimension = make_str("-1");
4834 $$.type_index = make_str("-1");
4835 $$.type_sizeof = NULL;
4837 else if (strcmp($1, "decimal") == 0)
4839 $$.type_enum = ECPGt_decimal;
4840 $$.type_str = make_str("decimal");
4841 $$.type_dimension = make_str("-1");
4842 $$.type_index = make_str("-1");
4843 $$.type_sizeof = NULL;
4845 else if (strcmp($1, "date") == 0)
4847 $$.type_enum = ECPGt_date;
4848 $$.type_str = make_str("date");
4849 $$.type_dimension = make_str("-1");
4850 $$.type_index = make_str("-1");
4851 $$.type_sizeof = NULL;
4853 else if (strcmp($1, "timestamp") == 0)
4855 $$.type_enum = ECPGt_timestamp;
4856 $$.type_str = make_str("timestamp");
4857 $$.type_dimension = make_str("-1");
4858 $$.type_index = make_str("-1");
4859 $$.type_sizeof = NULL;
4861 else if (strcmp($1, "interval") == 0)
4863 $$.type_enum = ECPGt_interval;
4864 $$.type_str = make_str("interval");
4865 $$.type_dimension = make_str("-1");
4866 $$.type_index = make_str("-1");
4867 $$.type_sizeof = NULL;
4869 else if (strcmp($1, "datetime") == 0)
4871 $$.type_enum = ECPGt_timestamp;
4872 $$.type_str = make_str("timestamp");
4873 $$.type_dimension = make_str("-1");
4874 $$.type_index = make_str("-1");
4875 $$.type_sizeof = NULL;
4879 /* this is for typedef'ed types */
4880 struct typedefs *this = get_typedef($1);
4882 $$.type_str = (this->type->type_enum == ECPGt_varchar) ? EMPTY : mm_strdup(this->name);
4883 $$.type_enum = this->type->type_enum;
4884 $$.type_dimension = this->type->type_dimension;
4885 $$.type_index = this->type->type_index;
4886 $$.type_sizeof = this->type->type_sizeof;
4887 struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list);
4890 | s_struct_union_symbol
4892 /* this is for named structs/unions */
4894 struct typedefs *this;
4895 bool forward = (forward_name != NULL && strcmp($1.symbol, forward_name) == 0 && strcmp($1.su, "struct") == 0);
4897 name = cat2_str($1.su, $1.symbol);
4898 /* Do we have a forward definition? */
4903 this = get_typedef(name);
4904 $$.type_str = mm_strdup(this->name);
4905 $$.type_enum = this->type->type_enum;
4906 $$.type_dimension = this->type->type_dimension;
4907 $$.type_index = this->type->type_index;
4908 $$.type_sizeof = this->type->type_sizeof;
4909 struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list);
4915 $$.type_enum = ECPGt_long;
4916 $$.type_dimension = make_str("-1");
4917 $$.type_index = make_str("-1");
4918 $$.type_sizeof = make_str("");
4919 struct_member_list[struct_level] = NULL;
4924 enum_type: SQL_ENUM symbol enum_definition
4925 { $$ = cat_str(3, make_str("enum"), $2, $3); }
4926 | SQL_ENUM enum_definition
4927 { $$ = cat2_str(make_str("enum"), $2); }
4929 { $$ = cat2_str(make_str("enum"), $2); }
4932 enum_definition: '{' c_list '}'
4933 { $$ = cat_str(3, make_str("{"), $2, make_str("}")); };
4935 struct_union_type_with_symbol: s_struct_union_symbol
4937 struct_member_list[struct_level++] = NULL;
4938 if (struct_level >= STRUCT_DEPTH)
4939 mmerror(PARSE_ERROR, ET_ERROR, "Too many levels in nested structure/union definition");
4940 forward_name = mm_strdup($1.symbol);
4942 '{' variable_declarations '}'
4944 struct typedefs *ptr, *this;
4945 struct this_type su_type;
4947 ECPGfree_struct_member(struct_member_list[struct_level]);
4948 struct_member_list[struct_level] = NULL;
4950 if (strncmp($1.su, "struct", sizeof("struct")-1) == 0)
4951 su_type.type_enum = ECPGt_struct;
4953 su_type.type_enum = ECPGt_union;
4954 su_type.type_str = cat2_str($1.su, $1.symbol);
4956 forward_name = NULL;
4958 /* This is essantially a typedef but needs the keyword struct/union as well.
4959 * So we create the typedef for each struct definition with symbol */
4960 for (ptr = types; ptr != NULL; ptr = ptr->next)
4962 if (strcmp(su_type.type_str, ptr->name) == 0)
4963 /* re-definition is a bug */
4964 mmerror(PARSE_ERROR, ET_ERROR, "Type %s already defined", su_type.type_str);
4967 this = (struct typedefs *) mm_alloc(sizeof(struct typedefs));
4969 /* initial definition */
4971 this->name = mm_strdup(su_type.type_str);
4972 this->brace_level = braces_open;
4973 this->type = (struct this_type *) mm_alloc(sizeof(struct this_type));
4974 this->type->type_enum = su_type.type_enum;
4975 this->type->type_str = mm_strdup(su_type.type_str);
4976 this->type->type_dimension = make_str("-1"); /* dimension of array */
4977 this->type->type_index = make_str("-1"); /* length of string */
4978 this->type->type_sizeof = ECPGstruct_sizeof;
4979 this->struct_member_list = struct_member_list[struct_level];
4982 $$ = cat_str(4, su_type.type_str, make_str("{"), $4, make_str("}"));
4986 struct_union_type: struct_union_type_with_symbol { $$ = $1; }
4989 struct_member_list[struct_level++] = NULL;
4990 if (struct_level >= STRUCT_DEPTH)
4991 mmerror(PARSE_ERROR, ET_ERROR, "Too many levels in nested structure/union definition");
4993 '{' variable_declarations '}'
4995 ECPGfree_struct_member(struct_member_list[struct_level]);
4996 struct_member_list[struct_level] = NULL;
4998 $$ = cat_str(4, $1, make_str("{"), $4, make_str("}"));
5002 s_struct_union_symbol: SQL_STRUCT symbol
5004 $$.su = make_str("struct");
5006 ECPGstruct_sizeof = cat_str(3, make_str("sizeof("), cat2_str(mm_strdup($$.su), mm_strdup($$.symbol)), make_str(")"));
5010 $$.su = make_str("union");
5015 s_struct_union: SQL_STRUCT
5017 ECPGstruct_sizeof = make_str(""); /* This must not be NULL to distinguish from simple types. */
5018 $$ = make_str("struct");
5020 | UNION { $$ = make_str("union"); }
5023 simple_type: unsigned_type { $$=$1; }
5024 | opt_signed signed_type { $$=$2; }
5027 unsigned_type: SQL_UNSIGNED SQL_SHORT { $$ = ECPGt_unsigned_short; }
5028 | SQL_UNSIGNED SQL_SHORT INT_P { $$ = ECPGt_unsigned_short; }
5029 | SQL_UNSIGNED { $$ = ECPGt_unsigned_int; }
5030 | SQL_UNSIGNED INT_P { $$ = ECPGt_unsigned_int; }
5031 | SQL_UNSIGNED SQL_LONG { $$ = ECPGt_unsigned_long; }
5032 | SQL_UNSIGNED SQL_LONG INT_P { $$ = ECPGt_unsigned_long; }
5033 | SQL_UNSIGNED SQL_LONG SQL_LONG
5035 #ifdef HAVE_LONG_LONG_INT_64
5036 $$ = ECPGt_unsigned_long_long;
5038 $$ = ECPGt_unsigned_long;
5041 | SQL_UNSIGNED SQL_LONG SQL_LONG INT_P
5043 #ifdef HAVE_LONG_LONG_INT_64
5044 $$ = ECPGt_unsigned_long_long;
5046 $$ = ECPGt_unsigned_long;
5049 | SQL_UNSIGNED CHAR_P { $$ = ECPGt_unsigned_char; }
5052 signed_type: SQL_SHORT { $$ = ECPGt_short; }
5053 | SQL_SHORT INT_P { $$ = ECPGt_short; }
5054 | INT_P { $$ = ECPGt_int; }
5055 | SQL_LONG { $$ = ECPGt_long; }
5056 | SQL_LONG INT_P { $$ = ECPGt_long; }
5059 #ifdef HAVE_LONG_LONG_INT_64
5060 $$ = ECPGt_long_long;
5065 | SQL_LONG SQL_LONG INT_P
5067 #ifdef HAVE_LONG_LONG_INT_64
5068 $$ = ECPGt_long_long;
5073 | SQL_BOOL { $$ = ECPGt_bool; }
5074 | CHAR_P { $$ = ECPGt_char; }
5075 | DOUBLE_P { $$ = ECPGt_double; }
5078 opt_signed: SQL_SIGNED
5082 variable_list: variable
5084 | variable_list ',' variable
5085 { $$ = cat_str(3, $1, make_str(","), $3); }
5088 variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer
5090 struct ECPGtype * type;
5091 char *dimension = $3.index1; /* dimension of array */
5092 char *length = $3.index2; /* length of string */
5095 adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1), false);
5097 switch (actual_type[struct_level].type_enum)
5101 if (atoi(dimension) < 0)
5102 type = ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof);
5104 type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof), dimension);
5106 $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4);
5110 if (atoi(dimension) < 0)
5111 type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
5113 type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
5115 if (strcmp(dimension, "0") == 0 || abs(atoi(dimension)) == 1)
5118 sprintf(dim, "[%s]", dimension);
5119 if (strcmp(length, "0") == 0)
5120 mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented");
5122 if (strcmp(dimension, "0") == 0)
5123 $$ = cat_str(6, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4);
5125 $$ = cat_str(7, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4);
5129 case ECPGt_unsigned_char:
5130 if (atoi(dimension) == -1)
5131 type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
5133 type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
5135 $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4);
5139 if (atoi(dimension) < 0)
5140 type = ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1"));
5142 type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1")), dimension);
5144 $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4);
5148 if (struct_level == 0)
5149 new_variable($2, type, braces_open);
5151 ECPGmake_struct_member($2, type, &(struct_member_list[struct_level - 1]));
5157 opt_initializer: /*EMPTY*/
5162 $$ = cat2_str(make_str("="), $2);
5166 opt_pointer: /*EMPTY*/ { $$ = EMPTY; }
5167 | '*' { $$ = make_str("*"); }
5168 | '*' '*' { $$ = make_str("**"); }
5172 * We try to simulate the correct DECLARE syntax here so we get dynamic SQL
5174 ECPGDeclare: DECLARE STATEMENT ident
5176 /* this is only supported for compatibility */
5177 $$ = cat_str(3, make_str("/* declare statement"), $3, make_str("*/"));
5181 * the exec sql disconnect statement: disconnect from the given database
5183 ECPGDisconnect: SQL_DISCONNECT dis_name { $$ = $2; }
5186 dis_name: connection_object { $$ = $1; }
5187 | SQL_CURRENT { $$ = make_str("\"CURRENT\""); }
5188 | ALL { $$ = make_str("\"ALL\""); }
5189 | /*EMPTY*/ { $$ = make_str("\"CURRENT\""); }
5192 connection_object: connection_target { $$ = $1; }
5193 | DEFAULT { $$ = make_str("\"DEFAULT\""); }
5197 * execute a given string as sql command
5199 ECPGExecute : EXECUTE IMMEDIATE execstring
5201 struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
5203 thisquery->type = &ecpg_query;
5204 thisquery->brace_level = 0;
5205 thisquery->next = NULL;
5206 thisquery->name = $3;
5208 add_variable_to_head(&argsinsert, thisquery, &no_indicator);
5212 | EXECUTE prepared_name
5214 struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
5216 thisquery->type = &ecpg_query;
5217 thisquery->brace_level = 0;
5218 thisquery->next = NULL;
5219 thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement()") + strlen($2));
5220 sprintf(thisquery->name, "ECPGprepared_statement(%s)", $2);
5222 add_variable_to_head(&argsinsert, thisquery, &no_indicator);
5230 execute_rest: ecpg_using ecpg_into { $$ = EMPTY; }
5231 | ecpg_into ecpg_using { $$ = EMPTY; }
5232 | ecpg_using { $$ = EMPTY; }
5233 | ecpg_into { $$ = EMPTY; }
5234 | /* EMPTY */ { $$ = EMPTY; }
5237 execstring: char_variable
5240 { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
5243 prepared_name: name { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
5244 | char_variable { $$ = $1; }
5248 * the exec sql free command to deallocate a previously
5249 * prepared statement
5251 ECPGFree: SQL_FREE name { $$ = $2; };
5254 * open is an open cursor, at the moment this has to be removed
5256 ECPGOpen: SQL_OPEN name opt_ecpg_using { $$ = $2; };
5258 opt_ecpg_using: /*EMPTY*/ { $$ = EMPTY; }
5259 | ecpg_using { $$ = $1; }
5262 ecpg_using: USING using_list { $$ = EMPTY; }
5263 | using_descriptor { $$ = $1; }
5266 using_descriptor: USING opt_sql SQL_DESCRIPTOR quoted_ident_stringvar
5268 add_variable_to_head(&argsinsert, descriptor_variable($4,0), &no_indicator);
5273 into_descriptor: INTO opt_sql SQL_DESCRIPTOR quoted_ident_stringvar
5275 add_variable_to_head(&argsresult, descriptor_variable($4,1), &no_indicator);
5280 opt_sql: /*EMPTY*/ | SQL_SQL;
5282 ecpg_into: INTO into_list { $$ = EMPTY; }
5283 | into_descriptor { $$ = $1; }
5286 using_list: UsingConst | UsingConst ',' using_list;
5288 UsingConst: AllConst
5290 if ($1[1] != '?') /* found a constant */
5292 char *length = mm_alloc(32);
5294 sprintf(length, "%d", (int) strlen($1));
5295 add_variable_to_head(&argsinsert, new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0), &no_indicator);
5298 | civarind { $$ = EMPTY; }
5302 * As long as the prepare statement is not supported by the backend, we will
5303 * try to simulate it here so we get dynamic SQL
5305 * It is supported now but not usable yet by ecpg.
5307 ECPGPrepare: PREPARE prepared_name FROM execstring
5308 { $$ = cat_str(3, $2, make_str(","), $4); }
5311 * We accept descibe but do nothing with it so far.
5313 ECPGDescribe: SQL_DESCRIBE INPUT_P name using_descriptor
5315 mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
5316 $$ = (char *) mm_alloc(sizeof("1, ECPGprepared_statement(\"\")") + strlen($3));
5317 sprintf($$, "1, ECPGprepared_statement(\"%s\")", $3);
5319 | SQL_DESCRIBE opt_output name using_descriptor
5321 mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
5322 $$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(\"\")") + strlen($3));
5323 sprintf($$, "0, ECPGprepared_statement(\"%s\")", $3);
5325 | SQL_DESCRIBE opt_output name into_descriptor
5327 mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
5328 $$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(\"\")") + strlen($3));
5329 sprintf($$, "0, ECPGprepared_statement(\"%s\")", $3);
5333 opt_output: SQL_OUTPUT { $$ = make_str("output"); }
5334 | /* EMPTY */ { $$ = EMPTY; }
5338 * dynamic SQL: descriptor based access
5339 * originall written by Christof Petig <christof.petig@wtal.de>
5340 * and Peter Eisentraut <peter.eisentraut@credativ.de>
5344 * allocate a descriptor
5346 ECPGAllocateDescr: SQL_ALLOCATE SQL_DESCRIPTOR quoted_ident_stringvar
5348 add_descriptor($3,connection);
5354 * deallocate a descriptor
5356 ECPGDeallocateDescr: DEALLOCATE SQL_DESCRIPTOR quoted_ident_stringvar
5358 drop_descriptor($3,connection);
5364 * manipulate a descriptor header
5367 ECPGGetDescriptorHeader: GET SQL_DESCRIPTOR quoted_ident_stringvar ECPGGetDescHeaderItems
5371 ECPGGetDescHeaderItems: ECPGGetDescHeaderItem
5372 | ECPGGetDescHeaderItems ',' ECPGGetDescHeaderItem
5375 ECPGGetDescHeaderItem: cvariable '=' desc_header_item
5376 { push_assignment($1, $3); }
5380 ECPGSetDescriptorHeader: SET SQL_DESCRIPTOR quoted_ident_stringvar ECPGSetDescHeaderItems
5384 ECPGSetDescHeaderItems: ECPGSetDescHeaderItem
5385 | ECPGSetDescHeaderItems ',' ECPGSetDescHeaderItem
5388 ECPGSetDescHeaderItem: desc_header_item '=' IntConstVar
5390 push_assignment($3, $1);
5395 desc_header_item: SQL_COUNT { $$ = ECPGd_count; }
5399 * manipulate a descriptor
5402 ECPGGetDescriptor: GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE IntConstVar ECPGGetDescItems
5403 { $$.str = $5; $$.name = $3; }
5406 ECPGGetDescItems: ECPGGetDescItem
5407 | ECPGGetDescItems ',' ECPGGetDescItem
5410 ECPGGetDescItem: cvariable '=' descriptor_item { push_assignment($1, $3); };
5413 ECPGSetDescriptor: SET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE IntConstVar ECPGSetDescItems
5414 { $$.str = $5; $$.name = $3; }
5417 ECPGSetDescItems: ECPGSetDescItem
5418 | ECPGSetDescItems ',' ECPGSetDescItem
5421 ECPGSetDescItem: descriptor_item '=' AllConstVar
5423 push_assignment($3, $1);
5428 descriptor_item: SQL_CARDINALITY { $$ = ECPGd_cardinality; }
5429 | SQL_DATA { $$ = ECPGd_data; }
5430 | SQL_DATETIME_INTERVAL_CODE { $$ = ECPGd_di_code; }
5431 | SQL_DATETIME_INTERVAL_PRECISION { $$ = ECPGd_di_precision; }
5432 | SQL_INDICATOR { $$ = ECPGd_indicator; }
5433 | SQL_KEY_MEMBER { $$ = ECPGd_key_member; }
5434 | SQL_LENGTH { $$ = ECPGd_length; }
5435 | SQL_NAME { $$ = ECPGd_name; }
5436 | SQL_NULLABLE { $$ = ECPGd_nullable; }
5437 | SQL_OCTET_LENGTH { $$ = ECPGd_octet; }
5438 | PRECISION { $$ = ECPGd_precision; }
5439 | SQL_RETURNED_LENGTH { $$ = ECPGd_length; }
5440 | SQL_RETURNED_OCTET_LENGTH { $$ = ECPGd_ret_octet; }
5441 | SQL_SCALE { $$ = ECPGd_scale; }
5442 | TYPE_P { $$ = ECPGd_type; }
5447 * for compatibility with ORACLE we will also allow the keyword RELEASE
5448 * after a transaction statement to disconnect from the database.
5451 ECPGRelease: TransactionStmt SQL_RELEASE
5453 if (strcmp($1, "begin") == 0)
5454 mmerror(PARSE_ERROR, ET_ERROR, "RELEASE does not make sense when beginning a transaction");
5456 fprintf(yyout, "ECPGtrans(__LINE__, %s, \"%s\");",
5457 connection ? connection : "NULL", $1);
5459 fprintf(yyout, "ECPGdisconnect(__LINE__, %s);",
5460 connection ? connection : "\"CURRENT\"");
5467 * set/reset the automatic transaction mode, this needs a differnet handling
5468 * as the other set commands
5470 ECPGSetAutocommit: SET SQL_AUTOCOMMIT '=' on_off { $$ = $4; }
5471 | SET SQL_AUTOCOMMIT TO on_off { $$ = $4; }
5474 on_off: ON { $$ = make_str("on"); }
5475 | OFF { $$ = make_str("off"); }
5479 * set the actual connection, this needs a differnet handling as the other
5482 ECPGSetConnection: SET SQL_CONNECTION TO connection_object { $$ = $4; }
5483 | SET SQL_CONNECTION '=' connection_object { $$ = $4; }
5484 | SET SQL_CONNECTION connection_object { $$ = $3; }
5488 * define a new type for embedded SQL
5492 /* reset this variable so we see if there was */
5493 /* an initializer specified */
5496 ECPGColLabelCommon IS var_type opt_array_bounds opt_reference
5498 /* add entry to list */
5499 struct typedefs *ptr, *this;
5500 char *dimension = $6.index1;
5501 char *length = $6.index2;
5503 if (($5.type_enum == ECPGt_struct ||
5504 $5.type_enum == ECPGt_union) &&
5506 mmerror(PARSE_ERROR, ET_ERROR, "Initializer not allowed in EXEC SQL TYPE command");
5509 for (ptr = types; ptr != NULL; ptr = ptr->next)
5511 if (strcmp($3, ptr->name) == 0)
5512 /* re-definition is a bug */
5513 mmerror(PARSE_ERROR, ET_ERROR, "Type %s already defined", $3);
5516 adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0, false);
5518 this = (struct typedefs *) mm_alloc(sizeof(struct typedefs));
5520 /* initial definition */
5523 this->brace_level = braces_open;
5524 this->type = (struct this_type *) mm_alloc(sizeof(struct this_type));
5525 this->type->type_enum = $5.type_enum;
5526 this->type->type_str = mm_strdup($3);
5527 this->type->type_dimension = dimension; /* dimension of array */
5528 this->type->type_index = length; /* length of string */
5529 this->type->type_sizeof = ECPGstruct_sizeof;
5530 this->struct_member_list = ($5.type_enum == ECPGt_struct || $5.type_enum == ECPGt_union) ?
5531 struct_member_list[struct_level] : NULL;
5533 if ($5.type_enum != ECPGt_varchar &&
5534 $5.type_enum != ECPGt_char &&
5535 $5.type_enum != ECPGt_unsigned_char &&
5536 atoi(this->type->type_index) >= 0)
5537 mmerror(PARSE_ERROR, ET_ERROR, "No multidimensional array support for simple data types");
5542 if (auto_create_c == false)
5543 $$ = cat_str(7, make_str("/* exec sql type"), mm_strdup($3), make_str("is"), mm_strdup($5.type_str), mm_strdup($6.str), $7, make_str("*/"));
5545 $$ = cat_str(6, make_str("typedef "), mm_strdup($5.type_str), *$7?make_str("*"):make_str(""), mm_strdup($6.str), mm_strdup($3), make_str(";"));
5549 opt_reference: SQL_REFERENCE { $$ = make_str("reference"); }
5550 | /*EMPTY*/ { $$ = EMPTY; }
5554 * define the type of one variable for embedded SQL
5558 /* reset this variable so we see if there was */
5559 /* an initializer specified */
5562 ColLabel IS var_type opt_array_bounds opt_reference
5564 struct variable *p = find_variable($3);
5565 char *dimension = $6.index1;
5566 char *length = $6.index2;
5567 struct ECPGtype * type;
5569 if (($5.type_enum == ECPGt_struct ||
5570 $5.type_enum == ECPGt_union) &&
5572 mmerror(PARSE_ERROR, ET_ERROR, "Initializer not allowed in EXEC SQL VAR command");
5575 adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0, false);
5577 switch ($5.type_enum)
5581 if (atoi(dimension) < 0)
5582 type = ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum, $5.type_sizeof);
5584 type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum,$5.type_sizeof), dimension);
5588 if (atoi(dimension) == -1)
5589 type = ECPGmake_simple_type($5.type_enum, length);
5591 type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension);
5595 case ECPGt_unsigned_char:
5596 if (atoi(dimension) == -1)
5597 type = ECPGmake_simple_type($5.type_enum, length);
5599 type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension);
5603 if (atoi(length) >= 0)
5604 mmerror(PARSE_ERROR, ET_ERROR, "No multidimensional array support for simple data types");
5606 if (atoi(dimension) < 0)
5607 type = ECPGmake_simple_type($5.type_enum, make_str("1"));
5609 type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, make_str("1")), dimension);
5613 ECPGfree_type(p->type);
5617 $$ = cat_str(7, make_str("/* exec sql var"), mm_strdup($3), make_str("is"), mm_strdup($5.type_str), mm_strdup($6.str), $7, make_str("*/"));
5622 * whenever statement: decide what to do in case of error/no data found
5623 * according to SQL standards we lack: SQLSTATE, CONSTRAINT and SQLEXCEPTION
5625 ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action
5627 when_error.code = $<action>3.code;
5628 when_error.command = $<action>3.command;
5629 $$ = cat_str(3, make_str("/* exec sql whenever sqlerror "), $3.str, make_str("; */\n"));
5631 | SQL_WHENEVER NOT SQL_FOUND action
5633 when_nf.code = $<action>4.code;
5634 when_nf.command = $<action>4.command;
5635 $$ = cat_str(3, make_str("/* exec sql whenever not found "), $4.str, make_str("; */\n"));
5637 | SQL_WHENEVER SQL_SQLWARNING action
5639 when_warn.code = $<action>3.code;
5640 when_warn.command = $<action>3.command;
5641 $$ = cat_str(3, make_str("/* exec sql whenever sql_warning "), $3.str, make_str("; */\n"));
5645 action : SQL_CONTINUE
5647 $<action>$.code = W_NOTHING;
5648 $<action>$.command = NULL;
5649 $<action>$.str = make_str("continue");
5653 $<action>$.code = W_SQLPRINT;
5654 $<action>$.command = NULL;
5655 $<action>$.str = make_str("sqlprint");
5659 $<action>$.code = W_STOP;
5660 $<action>$.command = NULL;
5661 $<action>$.str = make_str("stop");
5665 $<action>$.code = W_GOTO;
5666 $<action>$.command = strdup($2);
5667 $<action>$.str = cat2_str(make_str("goto "), $2);
5671 $<action>$.code = W_GOTO;
5672 $<action>$.command = strdup($3);
5673 $<action>$.str = cat2_str(make_str("goto "), $3);
5675 | DO name '(' c_args ')'
5677 $<action>$.code = W_DO;
5678 $<action>$.command = cat_str(4, $2, make_str("("), $4, make_str(")"));
5679 $<action>$.str = cat2_str(make_str("do"), mm_strdup($<action>$.command));
5683 $<action>$.code = W_BREAK;
5684 $<action>$.command = NULL;
5685 $<action>$.str = make_str("break");
5687 | SQL_CALL name '(' c_args ')'
5689 $<action>$.code = W_DO;
5690 $<action>$.command = cat_str(4, $2, make_str("("), $4, make_str(")"));
5691 $<action>$.str = cat2_str(make_str("call"), mm_strdup($<action>$.command));
5695 $<action>$.code = W_DO;
5696 $<action>$.command = cat_str(3, $2, make_str("("), make_str(")"));
5697 $<action>$.str = cat2_str(make_str("call"), mm_strdup($<action>$.command));
5701 /* some other stuff for ecpg */
5703 /* additional unreserved keywords */
5704 ECPGKeywords: ECPGKeywords_vanames { $$ = $1; }
5705 | ECPGKeywords_rest { $$ = $1; }
5708 ECPGKeywords_vanames: SQL_BREAK { $$ = make_str("break"); }
5709 | SQL_CALL { $$ = make_str("call"); }
5710 | SQL_CARDINALITY { $$ = make_str("cardinality"); }
5711 | SQL_CONTINUE { $$ = make_str("continue"); }
5712 | SQL_COUNT { $$ = make_str("count"); }
5713 | SQL_DATA { $$ = make_str("data"); }
5714 | SQL_DATETIME_INTERVAL_CODE { $$ = make_str("datetime_interval_code"); }
5715 | SQL_DATETIME_INTERVAL_PRECISION { $$ = make_str("datetime_interval_precision"); }
5716 | SQL_FOUND { $$ = make_str("found"); }
5717 | SQL_GO { $$ = make_str("go"); }
5718 | SQL_GOTO { $$ = make_str("goto"); }
5719 | SQL_IDENTIFIED { $$ = make_str("identified"); }
5720 | SQL_INDICATOR { $$ = make_str("indicator"); }
5721 | SQL_KEY_MEMBER { $$ = make_str("key_member"); }
5722 | SQL_LENGTH { $$ = make_str("length"); }
5723 | SQL_NAME { $$ = make_str("name"); }
5724 | SQL_NULLABLE { $$ = make_str("nullable"); }
5725 | SQL_OCTET_LENGTH { $$ = make_str("octet_length"); }
5726 | SQL_RELEASE { $$ = make_str("release"); }
5727 | SQL_RETURNED_LENGTH { $$ = make_str("returned_length"); }
5728 | SQL_RETURNED_OCTET_LENGTH { $$ = make_str("returned_octet_length"); }
5729 | SQL_SCALE { $$ = make_str("scale"); }
5730 | SQL_SECTION { $$ = make_str("section"); }
5731 | SQL_SQLERROR { $$ = make_str("sqlerror"); }
5732 | SQL_SQLPRINT { $$ = make_str("sqlprint"); }
5733 | SQL_SQLWARNING { $$ = make_str("sqlwarning"); }
5734 | SQL_STOP { $$ = make_str("stop"); }
5737 ECPGKeywords_rest: SQL_CONNECT { $$ = make_str("connect"); }
5738 | SQL_DESCRIBE { $$ = make_str("describe"); }
5739 | SQL_DISCONNECT { $$ = make_str("disconnect"); }
5740 | SQL_OPEN { $$ = make_str("open"); }
5741 | SQL_VAR { $$ = make_str("var"); }
5742 | SQL_WHENEVER { $$ = make_str("whenever"); }
5745 /* additional keywords that can be SQL type names (but not ECPGColLabels) */
5746 ECPGTypeName: SQL_BOOL { $$ = make_str("bool"); }
5747 | SQL_LONG { $$ = make_str("long"); }
5748 | SQL_OUTPUT { $$ = make_str("output"); }
5749 | SQL_SHORT { $$ = make_str("short"); }
5750 | SQL_STRUCT { $$ = make_str("struct"); }
5751 | SQL_SIGNED { $$ = make_str("signed"); }
5752 | SQL_UNSIGNED { $$ = make_str("unsigned"); }
5755 symbol: ColLabel { $$ = $1; }
5759 * Name classification hierarchy.
5761 * IDENT is the lexeme returned by the lexer for identifiers that match
5762 * no known keyword. In most cases, we can accept certain keywords as
5763 * names, not only IDENTs. We prefer to accept as many such keywords
5764 * as possible to minimize the impact of "reserved words" on programmers.
5765 * So, we divide names into several possible classes. The classification
5766 * is chosen in part to make keywords acceptable as names wherever possible.
5769 /* Column identifier --- names that can be column, table, etc names.
5771 ColId: ident { $$ = $1; }
5772 | unreserved_keyword { $$ = $1; }
5773 | col_name_keyword { $$ = $1; }
5774 | ECPGKeywords { $$ = $1; }
5775 | ECPGCKeywords { $$ = $1; }
5776 | CHAR_P { $$ = make_str("char"); }
5779 /* Type identifier --- names that can be type names.
5781 type_name: ident { $$ = $1; }
5782 | unreserved_keyword { $$ = $1; }
5783 | ECPGKeywords { $$ = $1; }
5784 | ECPGTypeName { $$ = $1; }
5785 | ECPGCKeywords { $$ = $1; }
5788 /* Function identifier --- names that can be function names.
5790 function_name: ident { $$ = $1; }
5791 | unreserved_keyword { $$ = $1; }
5792 | func_name_keyword { $$ = $1; }
5793 | ECPGKeywords { $$ = $1; }
5794 | ECPGCKeywords { $$ = $1; }
5797 /* Column label --- allowed labels in "AS" clauses.
5798 * This presently includes *all* Postgres keywords.
5800 ColLabel: ECPGColLabel { $$ = $1; }
5801 | ECPGTypeName { $$ = $1; }
5802 | CHAR_P { $$ = make_str("char"); }
5803 | INPUT_P { $$ = make_str("input"); }
5804 | INT_P { $$ = make_str("int"); }
5805 | UNION { $$ = make_str("union"); }
5806 | TO { $$ = make_str("to"); }
5807 | ECPGCKeywords { $$ = $1; }
5808 | ECPGunreserved_interval { $$ = $1; }
5811 ECPGColLabelCommon: ident { $$ = $1; }
5812 | col_name_keyword { $$ = $1; }
5813 | func_name_keyword { $$ = $1; }
5814 | ECPGKeywords_vanames { $$ = $1; }
5817 ECPGColLabel: ECPGColLabelCommon { $$ = $1; }
5818 | reserved_keyword { $$ = $1; }
5819 | ECPGunreserved { $$ = $1; }
5820 | ECPGKeywords_rest { $$ = $1; }
5823 ECPGCKeywords: S_AUTO { $$ = make_str("auto"); }
5824 | S_CONST { $$ = make_str("const"); }
5825 | S_EXTERN { $$ = make_str("extern"); }
5826 | S_REGISTER { $$ = make_str("register"); }
5827 | S_STATIC { $$ = make_str("static"); }
5828 | S_TYPEDEF { $$ = make_str("typedef"); }
5829 | S_VOLATILE { $$ = make_str("volatile"); }
5833 * Keyword classification lists. Generally, every keyword present in
5834 * the Postgres grammar should appear in exactly one of these lists.
5836 * Put a new keyword into the first list that it can go into without causing
5837 * shift or reduce conflicts. The earlier lists define "less reserved"
5838 * categories of keywords.
5841 /* "Unreserved" keywords --- available for use as any kind of name.
5843 /* The following symbols must be excluded from ECPGColLabel and directly included into ColLabel
5844 to enable C variables to get names from ECPGColLabel:
5845 DAY_P, HOUR_P, MINUTE_P, MONTH_P, SECOND_P, YEAR_P
5847 unreserved_keyword: ECPGunreserved_interval | ECPGunreserved;
5849 ECPGunreserved_interval: DAY_P { $$ = make_str("day"); }
5850 | HOUR_P { $$ = make_str("hour"); }
5851 | MINUTE_P { $$ = make_str("minute"); }
5852 | MONTH_P { $$ = make_str("month"); }
5853 | SECOND_P { $$ = make_str("second"); }
5854 | YEAR_P { $$ = make_str("year"); }
5857 ECPGunreserved: ABORT_P { $$ = make_str("abort"); }
5858 | ABSOLUTE_P { $$ = make_str("absolute"); }
5859 | ACCESS { $$ = make_str("access"); }
5860 | ACTION { $$ = make_str("action"); }
5861 | ADD { $$ = make_str("add"); }
5862 | AFTER { $$ = make_str("after"); }
5863 | AGGREGATE { $$ = make_str("aggregate"); }
5864 | ALSO { $$ = make_str("also"); }
5865 | ALTER { $$ = make_str("alter"); }
5866 | ASSERTION { $$ = make_str("assertion"); }
5867 | ASSIGNMENT { $$ = make_str("assignment"); }
5868 | AT { $$ = make_str("at"); }
5869 | BACKWARD { $$ = make_str("backward"); }
5870 | BEFORE { $$ = make_str("before"); }
5871 | BEGIN_P { $$ = make_str("begin"); }
5872 | BY { $$ = make_str("by"); }
5873 | CACHE { $$ = make_str("cache"); }
5874 | CASCADE { $$ = make_str("cascade"); }
5875 | CHAIN { $$ = make_str("chain"); }
5876 | CHARACTERISTICS { $$ = make_str("characteristics"); }
5877 | CHECKPOINT { $$ = make_str("checkpoint"); }
5878 | CLASS { $$ = make_str("class"); }
5879 | CLOSE { $$ = make_str("close"); }
5880 | CLUSTER { $$ = make_str("cluster"); }
5881 | COMMENT { $$ = make_str("comment"); }
5882 | COMMIT { $$ = make_str("commit"); }
5883 | COMMITTED { $$ = make_str("committed"); }
5884 | CONSTRAINTS { $$ = make_str("constraints"); }
5885 | CONVERSION_P { $$ = make_str("conversion"); }
5886 | COPY { $$ = make_str("copy"); }
5887 | CREATEDB { $$ = make_str("createdb"); }
5888 | CREATEUSER { $$ = make_str("createuser"); }
5889 | CSV { $$ = make_str("csv"); }
5890 | CURSOR { $$ = make_str("cursor"); }
5891 | CYCLE { $$ = make_str("cycle"); }
5892 | DATABASE { $$ = make_str("database"); }
5893 /* | DAY_P { $$ = make_str("day"); }*/
5894 | DEALLOCATE { $$ = make_str("deallocate"); }
5895 | DECLARE { $$ = make_str("declare"); }
5896 | DEFAULTS { $$ = make_str("defaults"); }
5897 | DEFERRED { $$ = make_str("deferred"); }
5898 | DELETE_P { $$ = make_str("delete"); }
5899 | DELIMITER { $$ = make_str("delimiter"); }
5900 | DELIMITERS { $$ = make_str("delimiters"); }
5901 | DOMAIN_P { $$ = make_str("domain"); }
5902 | DOUBLE_P { $$ = make_str("double"); }
5903 | DROP { $$ = make_str("drop"); }
5904 | EACH { $$ = make_str("each"); }
5905 | ENCODING { $$ = make_str("encoding"); }
5906 | ENCRYPTED { $$ = make_str("encrypted"); }
5907 | ESCAPE { $$ = make_str("escape"); }
5908 | EXCLUDING { $$ = make_str("excluding"); }
5909 | EXCLUSIVE { $$ = make_str("exclusive"); }
5910 | EXECUTE { $$ = make_str("execute"); }
5911 | EXPLAIN { $$ = make_str("explain"); }
5912 | FETCH { $$ = make_str("fetch"); }
5913 | FIRST_P { $$ = make_str("first"); }
5914 | FORCE { $$ = make_str("force"); }
5915 | FORWARD { $$ = make_str("forward"); }
5916 | FUNCTION { $$ = make_str("function"); }
5917 | GLOBAL { $$ = make_str("global"); }
5918 | HANDLER { $$ = make_str("handler"); }
5919 | HOLD { $$ = make_str("hold"); }
5920 /* | HOUR_P { $$ = make_str("hour"); }*/
5921 | IMMEDIATE { $$ = make_str("immediate"); }
5922 | IMMUTABLE { $$ = make_str("immutable"); }
5923 | IMPLICIT_P { $$ = make_str("implicit"); }
5924 | INCLUDING { $$ = make_str("including"); }
5925 | INCREMENT { $$ = make_str("increment"); }
5926 | INDEX { $$ = make_str("index"); }
5927 | INHERITS { $$ = make_str("inherits"); }
5928 | INSENSITIVE { $$ = make_str("insensitive"); }
5929 | INSERT { $$ = make_str("insert"); }
5930 | INSTEAD { $$ = make_str("instead"); }
5931 | ISOLATION { $$ = make_str("isolation"); }
5932 | KEY { $$ = make_str("key"); }
5933 | LANCOMPILER { $$ = make_str("lancompiler"); }
5934 | LANGUAGE { $$ = make_str("language"); }
5935 | LARGE_P { $$ = make_str("large"); }
5936 | LAST_P { $$ = make_str("last"); }
5937 | LEVEL { $$ = make_str("level"); }
5938 | LISTEN { $$ = make_str("listen"); }
5939 | LOAD { $$ = make_str("load"); }
5940 | LOCAL { $$ = make_str("local"); }
5941 | LOCATION { $$ = make_str("location"); }
5942 | LOCK_P { $$ = make_str("lock"); }
5943 | MATCH { $$ = make_str("match"); }
5944 | MAXVALUE { $$ = make_str("maxvalue"); }
5945 /* | MINUTE_P { $$ = make_str("minute"); }*/
5946 | MINVALUE { $$ = make_str("minvalue"); }
5947 | MODE { $$ = make_str("mode"); }
5948 /* | MONTH_P { $$ = make_str("month"); }*/
5949 | MOVE { $$ = make_str("move"); }
5950 | NAMES { $$ = make_str("names"); }
5951 | NEXT { $$ = make_str("next"); }
5952 | NO { $$ = make_str("no"); }
5953 | NOCREATEDB { $$ = make_str("nocreatedb"); }
5954 | NOCREATEUSER { $$ = make_str("nocreateuser"); }
5955 | NOTHING { $$ = make_str("nothing"); }
5956 | NOTIFY { $$ = make_str("notify"); }
5957 | OBJECT_P { $$ = make_str("object"); }
5958 | OF { $$ = make_str("of"); }
5959 | OIDS { $$ = make_str("oids"); }
5960 | OPERATOR { $$ = make_str("operator"); }
5961 | OPTION { $$ = make_str("option"); }
5962 | OWNER { $$ = make_str("owner"); }
5963 | PARTIAL { $$ = make_str("partial"); }
5964 | PASSWORD { $$ = make_str("password"); }
5965 | PREPARE { $$ = make_str("prepare"); }
5966 | PRESERVE { $$ = make_str("preserver"); }
5967 | PRIOR { $$ = make_str("prior"); }
5968 | PRIVILEGES { $$ = make_str("privileges"); }
5969 | PROCEDURAL { $$ = make_str("procedural"); }
5970 | PROCEDURE { $$ = make_str("procedure"); }
5971 | QUOTE { $$ = make_str("quote"); }
5972 | READ { $$ = make_str("read"); }
5973 | RECHECK { $$ = make_str("recheck"); }
5974 | REINDEX { $$ = make_str("reindex"); }
5975 | RELATIVE_P { $$ = make_str("relative"); }
5976 | RENAME { $$ = make_str("rename"); }
5977 | REPEATABLE { $$ = make_str("repeatable"); }
5978 | REPLACE { $$ = make_str("replace"); }
5979 | RESET { $$ = make_str("reset"); }
5980 | RESTART { $$ = make_str("restart"); }
5981 | RESTRICT { $$ = make_str("restrict"); }
5982 | RETURNS { $$ = make_str("returns"); }
5983 | REVOKE { $$ = make_str("revoke"); }
5984 | ROLLBACK { $$ = make_str("rollback"); }
5985 | ROWS { $$ = make_str("rows"); }
5986 | RULE { $$ = make_str("rule"); }
5987 | SCHEMA { $$ = make_str("schema"); }
5988 | SCROLL { $$ = make_str("scroll"); }
5989 /* | SECOND_P { $$ = make_str("second"); }*/
5990 | SEQUENCE { $$ = make_str("sequence"); }
5991 | SERIALIZABLE { $$ = make_str("serializable"); }
5992 | SESSION { $$ = make_str("session"); }
5993 | SET { $$ = make_str("set"); }
5994 | SHARE { $$ = make_str("share"); }
5995 | SHOW { $$ = make_str("show"); }
5996 | SIMPLE { $$ = make_str("simple"); }
5997 | STABLE { $$ = make_str("stable"); }
5998 | START { $$ = make_str("start"); }
5999 | STATEMENT { $$ = make_str("statement"); }
6000 | STATISTICS { $$ = make_str("statistics"); }
6001 | STDIN { $$ = make_str("stdin"); }
6002 | STDOUT { $$ = make_str("stdout"); }
6003 | STORAGE { $$ = make_str("storage"); }
6004 | STRICT_P { $$ = make_str("strict"); }
6005 | SYSID { $$ = make_str("sysid"); }
6006 | TABLESPACE { $$ = make_str("tablespace"); }
6007 | TEMP { $$ = make_str("temp"); }
6008 | TEMPLATE { $$ = make_str("template"); }
6009 | TEMPORARY { $$ = make_str("temporary"); }
6010 | TOAST { $$ = make_str("toast"); }
6011 | TRANSACTION { $$ = make_str("transaction"); }
6012 | TRIGGER { $$ = make_str("trigger"); }
6013 | TRUNCATE { $$ = make_str("truncate"); }
6014 | TRUSTED { $$ = make_str("trusted"); }
6015 | TYPE_P { $$ = make_str("type"); }
6016 | UNCOMMITTED { $$ = make_str("uncommitted"); }
6017 | UNENCRYPTED { $$ = make_str("unencrypted"); }
6018 | UNKNOWN { $$ = make_str("unknown"); }
6019 | UNLISTEN { $$ = make_str("unlisten"); }
6020 | UNTIL { $$ = make_str("until"); }
6021 | UPDATE { $$ = make_str("update"); }
6022 | USAGE { $$ = make_str("usage"); }
6023 | VACUUM { $$ = make_str("vacuum"); }
6024 | VALID { $$ = make_str("valid"); }
6025 | VALUES { $$ = make_str("values"); }
6026 | VARYING { $$ = make_str("varying"); }
6027 | VIEW { $$ = make_str("view"); }
6028 | WITH { $$ = make_str("with"); }
6029 | WITHOUT { $$ = make_str("without"); }
6030 | WORK { $$ = make_str("work"); }
6031 | WRITE { $$ = make_str("write"); }
6032 /* | YEAR_P { $$ = make_str("year"); }*/
6033 | ZONE { $$ = make_str("zone"); }
6036 /* Column identifier --- keywords that can be column, table, etc names.
6038 * Many of these keywords will in fact be recognized as type or function
6039 * names too; but they have special productions for the purpose, and so
6040 * can't be treated as "generic" type or function names.
6042 * The type names appearing here are not usable as function names
6043 * because they can be followed by '(' in typename productions, which
6044 * looks too much like a function call for an LR(1) parser.
6047 BIGINT { $$ = make_str("bigint");}
6048 | BIT { $$ = make_str("bit"); }
6049 /* CHAR must be excluded from ECPGColLabel because of conflict with UNSIGNED
6050 | CHAR_P { $$ = make_str("char"); }
6052 | CHARACTER { $$ = make_str("character"); }
6053 | COALESCE { $$ = make_str("coalesce"); }
6054 | CONVERT { $$ = make_str("convert"); }
6055 | DEC { $$ = make_str("dec"); }
6056 | DECIMAL_P { $$ = make_str("decimal"); }
6057 | EXISTS { $$ = make_str("exists"); }
6058 | EXTRACT { $$ = make_str("extract"); }
6059 | FLOAT_P { $$ = make_str("float"); }
6060 | INOUT { $$ = make_str("inout"); }
6061 /* INT must be excluded from ECPGColLabel because of conflict
6062 | INT_P { $$ = make_str("int"); }
6064 | INTEGER { $$ = make_str("integer"); }
6065 | INTERVAL { $$ = make_str("interval"); }
6066 | NATIONAL { $$ = make_str("national"); }
6067 | NCHAR { $$ = make_str("nchar"); }
6068 | NONE { $$ = make_str("none"); }
6069 | NULLIF { $$ = make_str("nullif"); }
6070 | NUMERIC { $$ = make_str("numeric"); }
6071 | OUT_P { $$ = make_str("out"); }
6072 | OVERLAY { $$ = make_str("overlay"); }
6073 | POSITION { $$ = make_str("position"); }
6074 | PRECISION { $$ = make_str("precision"); }
6075 | REAL { $$ = make_str("real"); }
6076 | ROW { $$ = make_str("row"); }
6077 | SETOF { $$ = make_str("setof"); }
6078 | SMALLINT { $$ = make_str("smallint"); }
6079 | SUBSTRING { $$ = make_str("substring"); }
6080 | TIME { $$ = make_str("time"); }
6081 | TIMESTAMP { $$ = make_str("timestamp"); }
6082 | TREAT { $$ = make_str("treat"); }
6083 | TRIM { $$ = make_str("trim"); }
6084 | VARCHAR { $$ = make_str("varchar"); }
6087 /* Function identifier --- keywords that can be function names.
6089 * Most of these are keywords that are used as operators in expressions;
6090 * in general such keywords can't be column names because they would be
6091 * ambiguous with variables, but they are unambiguous as function identifiers.
6093 * Do not include POSITION, SUBSTRING, etc here since they have explicit
6094 * productions in a_expr to support the goofy SQL9x argument syntax.
6095 * - thomas 2000-11-28
6098 AUTHORIZATION { $$ = make_str("authorization"); }
6099 | BETWEEN { $$ = make_str("between"); }
6100 | BINARY { $$ = make_str("binary"); }
6101 | CROSS { $$ = make_str("cross"); }
6102 | FREEZE { $$ = make_str("freeze"); }
6103 | FULL { $$ = make_str("full"); }
6104 | ILIKE { $$ = make_str("ilike"); }
6105 | INNER_P { $$ = make_str("inner"); }
6106 | IS { $$ = make_str("is"); }
6107 | ISNULL { $$ = make_str("isnull"); }
6108 | JOIN { $$ = make_str("join"); }
6109 | LEFT { $$ = make_str("left"); }
6110 | LIKE { $$ = make_str("like"); }
6111 | NATURAL { $$ = make_str("natural"); }
6112 | NOTNULL { $$ = make_str("notnull"); }
6113 | OUTER_P { $$ = make_str("outer"); }
6114 | OVERLAPS { $$ = make_str("overlaps"); }
6115 | RIGHT { $$ = make_str("right"); }
6116 | SIMILAR { $$ = make_str("similar"); }
6117 | VERBOSE { $$ = make_str("verbose"); }
6120 /* Reserved keyword --- these keywords are usable only as a ColLabel.
6122 * Keywords appear here if they could not be distinguished from variable,
6123 * type, or function names in some contexts. Don't put things here unless
6127 ALL { $$ = make_str("all"); }
6128 | ANALYSE { $$ = make_str("analyse"); } /* British */
6129 | ANALYZE { $$ = make_str("analyze"); }
6130 | AND { $$ = make_str("and"); }
6131 | ANY { $$ = make_str("any"); }
6132 | ARRAY { $$ = make_str("array"); }
6133 | AS { $$ = make_str("as"); }
6134 | ASC { $$ = make_str("asc"); }
6135 | BOTH { $$ = make_str("both"); }
6136 | CASE { $$ = make_str("case"); }
6137 | CAST { $$ = make_str("cast"); }
6138 | CHECK { $$ = make_str("check"); }
6139 | COLLATE { $$ = make_str("collate"); }
6140 | COLUMN { $$ = make_str("column"); }
6141 | CONSTRAINT { $$ = make_str("constraint"); }
6142 | CREATE { $$ = make_str("create"); }
6143 | CURRENT_DATE { $$ = make_str("current_date"); }
6144 | CURRENT_TIME { $$ = make_str("current_time"); }
6145 | CURRENT_TIMESTAMP { $$ = make_str("current_timestamp"); }
6146 | CURRENT_USER { $$ = make_str("current_user"); }
6147 | DEFAULT { $$ = make_str("default"); }
6148 | DEFERRABLE { $$ = make_str("deferrable"); }
6149 | DESC { $$ = make_str("desc"); }
6150 | DISTINCT { $$ = make_str("distinct"); }
6151 | DO { $$ = make_str("do"); }
6152 | ELSE { $$ = make_str("else"); }
6153 | END_P { $$ = make_str("end"); }
6154 | EXCEPT { $$ = make_str("except"); }
6155 | FALSE_P { $$ = make_str("false"); }
6156 | FOR { $$ = make_str("for"); }
6157 | FOREIGN { $$ = make_str("foreign"); }
6158 | FROM { $$ = make_str("from"); }
6159 | GRANT { $$ = make_str("grant"); }
6160 | GROUP_P { $$ = make_str("group"); }
6161 | HAVING { $$ = make_str("having"); }
6162 | IN_P { $$ = make_str("in"); }
6163 | INITIALLY { $$ = make_str("initially"); }
6164 | INTERSECT { $$ = make_str("intersect"); }
6165 | INTO { $$ = make_str("into"); }
6166 | LEADING { $$ = make_str("leading"); }
6167 | LIMIT { $$ = make_str("limit"); }
6168 | NEW { $$ = make_str("new"); }
6169 | NOT { $$ = make_str("not"); }
6170 | NOWAIT { $$ = make_str("nowait"); }
6171 | NULL_P { $$ = make_str("null"); }
6172 | OFF { $$ = make_str("off"); }
6173 | OFFSET { $$ = make_str("offset"); }
6174 | OLD { $$ = make_str("old"); }
6175 | ON { $$ = make_str("on"); }
6176 | ONLY { $$ = make_str("only"); }
6177 | OR { $$ = make_str("or"); }
6178 | ORDER { $$ = make_str("order"); }
6179 | PRIMARY { $$ = make_str("primary"); }
6180 | REFERENCES { $$ = make_str("references"); }
6181 | SELECT { $$ = make_str("select"); }
6182 | SESSION_USER { $$ = make_str("session_user"); }
6183 | SOME { $$ = make_str("some"); }
6184 | TABLE { $$ = make_str("table"); }
6185 | THEN { $$ = make_str("then"); }
6186 /* TO must be excluded from ECPGColLabel because of a conflict in variable name parsing
6187 | TO { $$ = make_str("to"); }
6189 | TRAILING { $$ = make_str("trailing"); }
6190 | TRUE_P { $$ = make_str("true"); }
6191 /* UNION must be excluded from ECPGColLabel because of conflict with s_union
6192 | UNION { $$ = make_str("union"); }
6194 | UNIQUE { $$ = make_str("unique"); }
6195 | USER { $$ = make_str("user"); }
6196 | USING { $$ = make_str("using"); }
6197 | WHEN { $$ = make_str("when"); }
6198 | WHERE { $$ = make_str("where"); }
6202 into_list : coutputvariable | into_list ',' coutputvariable
6205 ecpgstart: SQL_START { reset_variables(); }
6208 c_args: /*EMPTY*/ { $$ = EMPTY; }
6209 | c_list { $$ = $1; }
6212 coutputvariable: cvariable indicator
6213 { add_variable_to_head(&argsresult, find_variable($1), find_variable($2)); }
6215 { add_variable_to_head(&argsresult, find_variable($1), &no_indicator); }
6219 civarind: cvariable indicator
6221 if (find_variable($2)->type->type == ECPGt_array)
6222 mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input");
6224 add_variable_to_head(&argsinsert, find_variable($1), find_variable($2));
6225 $$ = create_questionmarks($1, false);
6231 add_variable_to_head(&argsinsert, find_variable($1), &no_indicator);
6232 $$ = create_questionmarks($1, false);
6236 indicator: cvariable { check_indicator((find_variable($1))->type); $$ = $1; }
6237 | SQL_INDICATOR cvariable { check_indicator((find_variable($2))->type); $$ = $2; }
6238 | SQL_INDICATOR name { check_indicator((find_variable($2))->type); $$ = $2; }
6241 cvariable: CVARIABLE
6243 /* As long as multidimensional arrays are not implemented we have to check for those here */
6245 int brace_open=0, brace = false;
6251 case '[': if (brace)
6253 mmerror(PARSE_ERROR, ET_FATAL, "No multidimensional array support for simple data types");
6257 case ']': brace_open--;
6258 if (brace_open == 0) brace = true;
6262 default: if (brace_open == 0) brace = false;
6270 ident: IDENT { $$ = $1; }
6271 | CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
6274 quoted_ident_stringvar: name
6275 { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
6277 { $$ = make3_str(make_str("("), $1, make_str(")")); }
6284 c_stuff_item: c_anything { $$ = $1; }
6285 | '(' ')' { $$ = make_str("()"); }
6287 { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
6290 c_stuff: c_stuff_item { $$ = $1; }
6291 | c_stuff c_stuff_item
6292 { $$ = cat2_str($1, $2); }
6295 c_list: c_term { $$ = $1; }
6296 | c_list ',' c_term { $$ = cat_str(3, $1, make_str(","), $3); }
6299 c_term: c_stuff { $$ = $1; }
6300 | '{' c_list '}' { $$ = cat_str(3, make_str("{"), $2, make_str("}")); }
6303 c_thing: c_anything { $$ = $1; }
6304 | '(' { $$ = make_str("("); }
6305 | ')' { $$ = make_str(")"); }
6306 | ',' { $$ = make_str(","); }
6307 | ';' { $$ = make_str(";"); }
6310 c_anything: IDENT { $$ = $1; }
6311 | CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
6312 | Iconst { $$ = $1; }
6313 | Fconst { $$ = $1; }
6314 | Sconst { $$ = $1; }
6315 | '*' { $$ = make_str("*"); }
6316 | '+' { $$ = make_str("+"); }
6317 | '-' { $$ = make_str("-"); }
6318 | '/' { $$ = make_str("/"); }
6319 | '%' { $$ = make_str("%"); }
6320 | NULL_P { $$ = make_str("NULL"); }
6321 | S_ADD { $$ = make_str("+="); }
6322 | S_AND { $$ = make_str("&&"); }
6323 | S_ANYTHING { $$ = make_name(); }
6324 | S_AUTO { $$ = make_str("auto"); }
6325 | S_CONST { $$ = make_str("const"); }
6326 | S_DEC { $$ = make_str("--"); }
6327 | S_DIV { $$ = make_str("/="); }
6328 | S_DOTPOINT { $$ = make_str(".*"); }
6329 | S_EQUAL { $$ = make_str("=="); }
6330 | S_EXTERN { $$ = make_str("extern"); }
6331 | S_INC { $$ = make_str("++"); }
6332 | S_LSHIFT { $$ = make_str("<<"); }
6333 | S_MEMBER { $$ = make_str("->"); }
6334 | S_MEMPOINT { $$ = make_str("->*"); }
6335 | S_MOD { $$ = make_str("%="); }
6336 | S_MUL { $$ = make_str("*="); }
6337 | S_NEQUAL { $$ = make_str("!="); }
6338 | S_OR { $$ = make_str("||"); }
6339 | S_REGISTER { $$ = make_str("register"); }
6340 | S_RSHIFT { $$ = make_str(">>"); }
6341 | S_STATIC { $$ = make_str("static"); }
6342 | S_SUB { $$ = make_str("-="); }
6343 | S_TYPEDEF { $$ = make_str("typedef"); }
6344 | S_VOLATILE { $$ = make_str("volatile"); }
6345 | SQL_BOOL { $$ = make_str("bool"); }
6346 | SQL_ENUM { $$ = make_str("enum"); }
6347 | HOUR_P { $$ = make_str("hour"); }
6348 | INT_P { $$ = make_str("int"); }
6349 | SQL_LONG { $$ = make_str("long"); }
6350 | MINUTE_P { $$ = make_str("minute"); }
6351 | MONTH_P { $$ = make_str("month"); }
6352 | SECOND_P { $$ = make_str("second"); }
6353 | SQL_SHORT { $$ = make_str("short"); }
6354 | SQL_SIGNED { $$ = make_str("signed"); }
6355 | SQL_STRUCT { $$ = make_str("struct"); }
6356 | SQL_UNSIGNED { $$ = make_str("unsigned"); }
6357 | YEAR_P { $$ = make_str("year"); }
6358 | CHAR_P { $$ = make_str("char"); }
6359 | FLOAT_P { $$ = make_str("float"); }
6360 | TO { $$ = make_str("to"); }
6361 | UNION { $$ = make_str("union"); }
6362 | VARCHAR { $$ = make_str("varchar"); }
6363 | '[' { $$ = make_str("["); }
6364 | ']' { $$ = make_str("]"); }
6365 | '=' { $$ = make_str("="); }
6370 void yyerror( char * error)
6374 snprintf(buf,sizeof buf,"%s at or near \"%s\"", error, token_start ? token_start : yytext);
6375 buf[sizeof(buf)-1]=0;
6376 mmerror(PARSE_ERROR, ET_ERROR, buf);