diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1d39674..fa6612d 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -109,15 +109,12 @@ static Node *makeIntConst(int val, int location); static Node *makeFloatConst(char *str, int location); static Node *makeBitStringConst(char *str, int location); static Node *makeNullAConst(int location); -static Node *makeAConst(Value *v, int location); static Node *makeBoolAConst(bool state, int location); static FuncCall *makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner); static void check_qualified_name(List *names, core_yyscan_t yyscanner); static List *check_func_name(List *names, core_yyscan_t yyscanner); static List *check_indirection(List *indirection, core_yyscan_t yyscanner); -static List *extractArgTypes(List *parameters); -static SelectStmt *findLeftmostSelect(SelectStmt *node); static void insertSelectOptions(SelectStmt *stmt, List *sortClause, List *lockingClause, Node *limitOffset, Node *limitCount, @@ -129,12 +126,6 @@ static void doNegateFloat(Value *v); static Node *makeAArrayExpr(List *elements, int location); static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args, int location); -static List *mergeTableFuncParameters(List *func_args, List *columns); -static TypeName *TableFuncTypeName(List *columns); -static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner); -static void SplitColQualList(List *qualList, - List **constraintList, CollateClause **collClause, - core_yyscan_t yyscanner); %} @@ -184,148 +175,48 @@ static void SplitColQualList(List *qualList, VariableSetStmt *vsetstmt; } -%type stmt schema_stmt - AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt - AlterFdwStmt AlterForeignServerStmt AlterGroupStmt - AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt - AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt - AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt - AlterRoleStmt AlterRoleSetStmt - AlterDefaultPrivilegesStmt DefACLAction - AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt - ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt - CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt - CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt - CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt - CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt - CreateAssertStmt CreateTrigStmt - CreateUserStmt CreateUserMappingStmt CreateRoleStmt - CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt - DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt - DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt - DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt - DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt - GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt - LockStmt NotifyStmt ExplainableStmt PreparableStmt - CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt - RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt - RuleActionStmt RuleActionStmtOrEmpty RuleStmt - SecLabelStmt SelectStmt TransactionStmt TruncateStmt - UnlistenStmt UpdateStmt VacuumStmt - VariableResetStmt VariableSetStmt VariableShowStmt - ViewStmt CheckPointStmt CreateConversionStmt - DeallocateStmt PrepareStmt ExecuteStmt - DropOwnedStmt ReassignOwnedStmt - AlterTSConfigurationStmt AlterTSDictionaryStmt +%type stmt + DeleteStmt + InsertStmt + PreparableStmt + SelectStmt + UpdateStmt %type select_no_parens select_with_parens select_clause simple_select values_clause -%type alter_column_default opclass_item opclass_drop alter_using -%type add_drop opt_asc_desc opt_nulls_order +%type opt_asc_desc opt_nulls_order -%type alter_table_cmd alter_type_cmd opt_collate_clause -%type alter_table_cmds alter_type_cmds +%type opt_collate_clause -%type opt_drop_behavior +%type opt_nowait -%type createdb_opt_list alterdb_opt_list copy_opt_list - transaction_mode_list - create_extension_opt_list alter_extension_opt_list -%type createdb_opt_item alterdb_opt_item copy_opt_item - transaction_mode_item - create_extension_opt_item alter_extension_opt_item +%type attr_name + name cursor_name -%type opt_lock lock_type cast_context -%type vacuum_option_list vacuum_option_elem -%type opt_force opt_or_replace - opt_grant_grant_option opt_grant_admin_option - opt_nowait opt_if_exists opt_with_data +%type func_name qual_Op qual_all_Op subquery_Op -%type OptRoleList AlterOptRoleList -%type CreateOptRoleElem AlterOptRoleElem - -%type opt_type -%type foreign_server_version opt_foreign_server_version -%type auth_ident -%type opt_in_database - -%type OptSchemaName -%type OptSchemaEltList - -%type TriggerForSpec TriggerForType -%type TriggerActionTime -%type TriggerEvents TriggerOneEvent -%type TriggerFuncArg -%type TriggerWhen - -%type copy_file_name - database_name access_method_clause access_method attr_name - name cursor_name file_name - index_name opt_index_name cluster_index_specification - -%type func_name handler_name qual_Op qual_all_Op subquery_Op - opt_class opt_inline_handler opt_validator validator_clause - opt_collate - -%type qualified_name OptConstrFromTable +%type qualified_name %type all_Op MathOp -%type iso_level opt_encoding -%type grantee -%type grantee_list -%type privilege -%type privileges privilege_list -%type privilege_target -%type function_with_argtypes -%type function_with_argtypes_list -%type defacl_privilege_target -%type DefACLOption -%type DefACLOptionList - %type stmtblock stmtmulti - OptTableElementList TableElementList OptInherit definition - OptTypedTableElementList TypedTableElementList - OptForeignTableElementList ForeignTableElementList - reloptions opt_reloptions - OptWith opt_distinct opt_definition func_args func_args_list - func_args_with_defaults func_args_with_defaults_list - func_as createfunc_opt_list alterfunc_opt_list - aggr_args old_aggr_definition old_aggr_list - oper_argtypes RuleActionList RuleActionMulti - opt_column_list columnList opt_name_list - sort_clause opt_sort_clause sortby_list index_params + opt_distinct + opt_name_list + sort_clause opt_sort_clause sortby_list name_list from_clause from_list opt_array_bounds - qualified_name_list any_name any_name_list + qualified_name_list any_name any_operator expr_list attrs target_list insert_column_list set_target_list set_clause_list set_clause multiple_set_clause - ctext_expr_list ctext_row def_list indirection opt_indirection - reloption_list group_clause TriggerFuncArgs select_limit - opt_select_limit opclass_item_list opclass_drop_list - opclass_purpose opt_opfamily transaction_mode_list_or_empty - OptTableFuncElementList TableFuncElementList opt_type_modifiers - prep_type_clause - execute_param_clause using_clause returning_clause - opt_enum_val_list enum_val_list table_func_column_list - create_generic_options alter_generic_options - relation_expr_list dostmt_opt_list - -%type opt_fdw_options fdw_options -%type fdw_option + ctext_expr_list ctext_row indirection opt_indirection + group_clause select_limit + opt_select_limit + TableFuncElementList opt_type_modifiers + using_clause returning_clause %type OptTempTableName -%type into_clause create_as_target - -%type createfunc_opt_item common_func_opt_item dostmt_opt_item -%type func_arg func_arg_with_default table_func_column -%type arg_class -%type func_return func_type - -%type opt_trusted opt_restart_seqs -%type OptTemp -%type OnCommitOption +%type into_clause %type for_locking_item %type for_locking_clause opt_for_locking_clause for_locking_items @@ -340,69 +231,32 @@ static void SplitColQualList(List *qualList, %type opt_interval interval_second %type overlay_placing substr_from substr_for -%type opt_instead -%type opt_unique opt_concurrently opt_verbose opt_full -%type opt_freeze opt_default opt_recheck -%type opt_binary opt_oids copy_delimiter - -%type copy_from - -%type opt_column event cursor_options opt_hold opt_set_data -%type reindex_type drop_type comment_type security_label_type - -%type fetch_args limit_clause select_limit_value +%type limit_clause select_limit_value offset_clause select_offset_value select_offset_value2 opt_select_fetch_first_value %type row_or_rows first_or_next -%type OptSeqOptList SeqOptList -%type SeqOptElem - %type insert_rest -%type set_rest SetResetClause - -%type TableElement TypedTableElement ConstraintElem TableFuncElement - ForeignTableElement -%type columnDef columnOptions -%type def_elem reloption_elem old_aggr_elem -%type def_arg columnElem where_clause where_or_current_clause +%type TableFuncElement +%type where_clause where_or_current_clause a_expr b_expr c_expr func_expr AexprConst indirection_el columnref in_expr having_clause func_table array_expr - ExclusionWhereClause -%type ExclusionConstraintList ExclusionConstraintElem %type func_arg_list %type func_arg_expr %type row type_list array_expr_list %type case_expr case_arg when_clause case_default %type when_clause_list %type sub_type -%type OptCreateAs CreateAsList -%type CreateAsElement ctext_expr -%type NumericOnly -%type NumericOnly_list +%type ctext_expr %type alias_clause %type sortby -%type index_elem %type table_ref %type joined_table %type relation_expr %type relation_expr_opt_alias %type target_el single_set_clause set_target insert_column_item -%type generic_option_name -%type generic_option_arg -%type generic_option_elem alter_generic_option_elem -%type generic_option_list alter_generic_option_list -%type explain_option_name -%type explain_option_arg -%type explain_option_elem -%type explain_option_list -%type copy_generic_opt_arg copy_generic_opt_arg_list_item -%type copy_generic_opt_elem -%type copy_generic_opt_list copy_generic_opt_arg_list -%type copy_options - %type Typename SimpleTypename ConstTypename GenericType Numeric opt_float Character ConstCharacter @@ -415,31 +269,12 @@ static void SplitColQualList(List *qualList, %type opt_varying opt_timezone %type Iconst SignedIconst -%type Sconst comment_text notify_payload -%type RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst -%type var_list -%type ColId ColLabel var_name type_function_name param_name -%type var_value zone_value +%type Sconst +%type ColId ColLabel type_function_name param_name %type unreserved_keyword type_func_name_keyword %type col_name_keyword reserved_keyword -%type TableConstraint TableLikeClause -%type TableLikeOptionList TableLikeOption -%type ColQualList -%type ColConstraint ColConstraintElem ConstraintAttr -%type key_actions key_delete key_match key_update key_action -%type ConstraintAttributeSpec ConstraintDeferrabilitySpec - ConstraintTimeSpec -%type ExistingIndex - -%type constraints_set_list -%type constraints_set_mode -%type OptTableSpace OptConsTableSpace OptTableSpaceOwner -%type opt_check_option - -%type opt_provider security_label - %type xml_attribute_el %type xml_attribute_list xml_attributes %type xml_root_version opt_xml_root_standalone @@ -478,82 +313,75 @@ static void SplitColQualList(List *qualList, */ /* ordinary key words in alphabetical order */ -%token ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER - AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC - ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION +%token + ALL ANALYSE ANALYZE AND ANY ARRAY AS ASC + ASYMMETRIC AT AUTHORIZATION - BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT + BETWEEN BIGINT BINARY BIT BOOLEAN_P BOTH BY - CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P - CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE - CLUSTER COALESCE COLLATE COLLATION COLUMN COMMENT COMMENTS COMMIT - COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS - CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE - CROSS CSV CURRENT_P + CASE CAST CHAR_P + CHARACTER CHECK + COALESCE COLLATE COLUMN + CONCURRENTLY CONSTRAINT + CONTENT_P CREATE + CROSS CURRENT_P CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA - CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE + CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR - DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS - DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC - DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP + DAY_P DEC DECIMAL_P DEFAULT + DEFERRABLE DELETE_P DELIMITER DELIMITERS DESC + DISTINCT DO DOCUMENT_P DOUBLE_P - EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT - EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN - EXTENSION EXTERNAL EXTRACT + ELSE END_P ESCAPE EXCEPT + EXISTS + EXTRACT - FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD - FREEZE FROM FULL FUNCTION FUNCTIONS + FALSE_P FETCH FIRST_P FLOAT_P FOLLOWING FOR FOREIGN + FREEZE FROM FULL - GLOBAL GRANT GRANTED GREATEST GROUP_P + GLOBAL GRANT GREATEST GROUP_P - HANDLER HAVING HEADER_P HOLD HOUR_P + HAVING HOUR_P - IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P - INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P - INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER - INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION + ILIKE IN_P + INITIALLY + INNER_P INOUT INSERT INT_P INTEGER + INTERSECT INTERVAL INTO IS ISNULL JOIN - KEY - - LABEL LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING - LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP - LOCATION LOCK_P + LAST_P LEADING + LEAST LEFT LIKE LIMIT LISTEN LOCAL LOCALTIME LOCALTIMESTAMP - MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE + MINUTE_P MONTH_P - NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NONE - NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF + NAME_P NATIONAL NATURAL NCHAR NEXT NO NONE + NOT NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC - OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR - ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER - - PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POSITION - PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY - PRIOR PRIVILEGES PROCEDURAL PROCEDURE + OF OFFSET ON ONLY OPERATOR OR + ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY - QUOTE + PARTITION PASSING PLACING POSITION + PRECEDING PRECISION PRESERVE PRIMARY - RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REINDEX - RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA - RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK - ROW ROWS RULE + RANGE READ REAL RECURSIVE REF REFERENCES + RETURNING RIGHT + ROW ROWS - SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES - SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE - SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT - STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING - SYMMETRIC SYSID SYSTEM_P + SECOND_P SELECT + SESSION_USER SET SETOF SHARE + SIMILAR SMALLINT SOME STANDALONE_P + STRIP_P SUBSTRING + SYMMETRIC - TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP - TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P - TRUNCATE TRUSTED TYPE_P + TABLE TEMP TEMPORARY TEXT_P THEN TIME TIMESTAMP + TO TRAILING TREAT TRIM TRUE_P + TYPE_P - UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNLOGGED - UNTIL UPDATE USER USING + UNBOUNDED UNION UNIQUE UNKNOWN UNLOGGED + UPDATE USER USING VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING VERBOSE VERSION_P VIEW VOLATILE @@ -667,1342 +495,14 @@ stmtmulti: stmtmulti ';' stmt ; stmt : - AlterDatabaseStmt - | AlterDatabaseSetStmt - | AlterDefaultPrivilegesStmt - | AlterDomainStmt - | AlterEnumStmt - | AlterExtensionStmt - | AlterExtensionContentsStmt - | AlterFdwStmt - | AlterForeignServerStmt - | AlterForeignTableStmt - | AlterFunctionStmt - | AlterGroupStmt - | AlterObjectSchemaStmt - | AlterOwnerStmt - | AlterSeqStmt - | AlterTableStmt - | AlterCompositeTypeStmt - | AlterRoleSetStmt - | AlterRoleStmt - | AlterTSConfigurationStmt - | AlterTSDictionaryStmt - | AlterUserMappingStmt - | AlterUserSetStmt - | AlterUserStmt - | AnalyzeStmt - | CheckPointStmt - | ClosePortalStmt - | ClusterStmt - | CommentStmt - | ConstraintsSetStmt - | CopyStmt - | CreateAsStmt - | CreateAssertStmt - | CreateCastStmt - | CreateConversionStmt - | CreateDomainStmt - | CreateExtensionStmt - | CreateFdwStmt - | CreateForeignServerStmt - | CreateForeignTableStmt - | CreateFunctionStmt - | CreateGroupStmt - | CreateOpClassStmt - | CreateOpFamilyStmt - | AlterOpFamilyStmt - | CreatePLangStmt - | CreateSchemaStmt - | CreateSeqStmt - | CreateStmt - | CreateTableSpaceStmt - | CreateTrigStmt - | CreateRoleStmt - | CreateUserStmt - | CreateUserMappingStmt - | CreatedbStmt - | DeallocateStmt - | DeclareCursorStmt - | DefineStmt - | DeleteStmt - | DiscardStmt - | DoStmt - | DropAssertStmt - | DropCastStmt - | DropFdwStmt - | DropForeignServerStmt - | DropGroupStmt - | DropOpClassStmt - | DropOpFamilyStmt - | DropOwnedStmt - | DropPLangStmt - | DropRuleStmt - | DropStmt - | DropTableSpaceStmt - | DropTrigStmt - | DropRoleStmt - | DropUserStmt - | DropUserMappingStmt - | DropdbStmt - | ExecuteStmt - | ExplainStmt - | FetchStmt - | GrantStmt - | GrantRoleStmt - | IndexStmt + DeleteStmt | InsertStmt - | ListenStmt - | LoadStmt - | LockStmt - | NotifyStmt - | PrepareStmt - | ReassignOwnedStmt - | ReindexStmt - | RemoveAggrStmt - | RemoveFuncStmt - | RemoveOperStmt - | RenameStmt - | RevokeStmt - | RevokeRoleStmt - | RuleStmt - | SecLabelStmt | SelectStmt - | TransactionStmt - | TruncateStmt - | UnlistenStmt | UpdateStmt - | VacuumStmt - | VariableResetStmt - | VariableSetStmt - | VariableShowStmt - | ViewStmt | /*EMPTY*/ { $$ = NULL; } ; -/***************************************************************************** - * - * Create a new Postgres DBMS role - * - *****************************************************************************/ - -CreateRoleStmt: - CREATE ROLE RoleId opt_with OptRoleList - { - CreateRoleStmt *n = makeNode(CreateRoleStmt); - n->stmt_type = ROLESTMT_ROLE; - n->role = $3; - n->options = $5; - $$ = (Node *)n; - } - ; - - -opt_with: WITH {} - | /*EMPTY*/ {} - ; - -/* - * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER - * for backwards compatibility). Note: the only option required by SQL99 - * is "WITH ADMIN name". - */ -OptRoleList: - OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); } - | /* EMPTY */ { $$ = NIL; } - ; - -AlterOptRoleList: - AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); } - | /* EMPTY */ { $$ = NIL; } - ; - -AlterOptRoleElem: - PASSWORD Sconst - { - $$ = makeDefElem("password", - (Node *)makeString($2)); - } - | PASSWORD NULL_P - { - $$ = makeDefElem("password", NULL); - } - | ENCRYPTED PASSWORD Sconst - { - $$ = makeDefElem("encryptedPassword", - (Node *)makeString($3)); - } - | UNENCRYPTED PASSWORD Sconst - { - $$ = makeDefElem("unencryptedPassword", - (Node *)makeString($3)); - } - | INHERIT - { - $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE)); - } - | CONNECTION LIMIT SignedIconst - { - $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3)); - } - | VALID UNTIL Sconst - { - $$ = makeDefElem("validUntil", (Node *)makeString($3)); - } - /* Supported but not documented for roles, for use by ALTER GROUP. */ - | USER name_list - { - $$ = makeDefElem("rolemembers", (Node *)$2); - } - | IDENT - { - /* - * We handle identifiers that aren't parser keywords with - * the following special-case codes, to avoid bloating the - * size of the main parser. - */ - if (strcmp($1, "superuser") == 0) - $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE)); - else if (strcmp($1, "nosuperuser") == 0) - $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE)); - else if (strcmp($1, "createuser") == 0) - { - /* For backwards compatibility, synonym for SUPERUSER */ - $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE)); - } - else if (strcmp($1, "nocreateuser") == 0) - { - /* For backwards compatibility, synonym for SUPERUSER */ - $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE)); - } - else if (strcmp($1, "createrole") == 0) - $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE)); - else if (strcmp($1, "nocreaterole") == 0) - $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE)); - else if (strcmp($1, "replication") == 0) - $$ = makeDefElem("isreplication", (Node *)makeInteger(TRUE)); - else if (strcmp($1, "noreplication") == 0) - $$ = makeDefElem("isreplication", (Node *)makeInteger(FALSE)); - else if (strcmp($1, "createdb") == 0) - $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE)); - else if (strcmp($1, "nocreatedb") == 0) - $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE)); - else if (strcmp($1, "login") == 0) - $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE)); - else if (strcmp($1, "nologin") == 0) - $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE)); - else if (strcmp($1, "noinherit") == 0) - { - /* - * Note that INHERIT is a keyword, so it's handled by main parser, but - * NOINHERIT is handled here. - */ - $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE)); - } - else - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("unrecognized role option \"%s\"", $1), - parser_errposition(@1))); - } - ; - -CreateOptRoleElem: - AlterOptRoleElem { $$ = $1; } - /* The following are not supported by ALTER ROLE/USER/GROUP */ - | SYSID Iconst - { - $$ = makeDefElem("sysid", (Node *)makeInteger($2)); - } - | ADMIN name_list - { - $$ = makeDefElem("adminmembers", (Node *)$2); - } - | ROLE name_list - { - $$ = makeDefElem("rolemembers", (Node *)$2); - } - | IN_P ROLE name_list - { - $$ = makeDefElem("addroleto", (Node *)$3); - } - | IN_P GROUP_P name_list - { - $$ = makeDefElem("addroleto", (Node *)$3); - } - ; - - -/***************************************************************************** - * - * Create a new Postgres DBMS user (role with implied login ability) - * - *****************************************************************************/ - -CreateUserStmt: - CREATE USER RoleId opt_with OptRoleList - { - CreateRoleStmt *n = makeNode(CreateRoleStmt); - n->stmt_type = ROLESTMT_USER; - n->role = $3; - n->options = $5; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * Alter a postgresql DBMS role - * - *****************************************************************************/ - -AlterRoleStmt: - ALTER ROLE RoleId opt_with AlterOptRoleList - { - AlterRoleStmt *n = makeNode(AlterRoleStmt); - n->role = $3; - n->action = +1; /* add, if there are members */ - n->options = $5; - $$ = (Node *)n; - } - ; - -opt_in_database: - /* EMPTY */ { $$ = NULL; } - | IN_P DATABASE database_name { $$ = $3; } - ; - -AlterRoleSetStmt: - ALTER ROLE RoleId opt_in_database SetResetClause - { - AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt); - n->role = $3; - n->database = $4; - n->setstmt = $5; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * Alter a postgresql DBMS user - * - *****************************************************************************/ - -AlterUserStmt: - ALTER USER RoleId opt_with AlterOptRoleList - { - AlterRoleStmt *n = makeNode(AlterRoleStmt); - n->role = $3; - n->action = +1; /* add, if there are members */ - n->options = $5; - $$ = (Node *)n; - } - ; - - -AlterUserSetStmt: - ALTER USER RoleId SetResetClause - { - AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt); - n->role = $3; - n->database = NULL; - n->setstmt = $4; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * Drop a postgresql DBMS role - * - * XXX Ideally this would have CASCADE/RESTRICT options, but since a role - * might own objects in multiple databases, there is presently no way to - * implement either cascading or restricting. Caveat DBA. - *****************************************************************************/ - -DropRoleStmt: - DROP ROLE name_list - { - DropRoleStmt *n = makeNode(DropRoleStmt); - n->missing_ok = FALSE; - n->roles = $3; - $$ = (Node *)n; - } - | DROP ROLE IF_P EXISTS name_list - { - DropRoleStmt *n = makeNode(DropRoleStmt); - n->missing_ok = TRUE; - n->roles = $5; - $$ = (Node *)n; - } - ; - -/***************************************************************************** - * - * Drop a postgresql DBMS user - * - * XXX Ideally this would have CASCADE/RESTRICT options, but since a user - * might own objects in multiple databases, there is presently no way to - * implement either cascading or restricting. Caveat DBA. - *****************************************************************************/ - -DropUserStmt: - DROP USER name_list - { - DropRoleStmt *n = makeNode(DropRoleStmt); - n->missing_ok = FALSE; - n->roles = $3; - $$ = (Node *)n; - } - | DROP USER IF_P EXISTS name_list - { - DropRoleStmt *n = makeNode(DropRoleStmt); - n->roles = $5; - n->missing_ok = TRUE; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * Create a postgresql group (role without login ability) - * - *****************************************************************************/ - -CreateGroupStmt: - CREATE GROUP_P RoleId opt_with OptRoleList - { - CreateRoleStmt *n = makeNode(CreateRoleStmt); - n->stmt_type = ROLESTMT_GROUP; - n->role = $3; - n->options = $5; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * Alter a postgresql group - * - *****************************************************************************/ - -AlterGroupStmt: - ALTER GROUP_P RoleId add_drop USER name_list - { - AlterRoleStmt *n = makeNode(AlterRoleStmt); - n->role = $3; - n->action = $4; - n->options = list_make1(makeDefElem("rolemembers", - (Node *)$6)); - $$ = (Node *)n; - } - ; - -add_drop: ADD_P { $$ = +1; } - | DROP { $$ = -1; } - ; - - -/***************************************************************************** - * - * Drop a postgresql group - * - * XXX see above notes about cascading DROP USER; groups have same problem. - *****************************************************************************/ - -DropGroupStmt: - DROP GROUP_P name_list - { - DropRoleStmt *n = makeNode(DropRoleStmt); - n->missing_ok = FALSE; - n->roles = $3; - $$ = (Node *)n; - } - | DROP GROUP_P IF_P EXISTS name_list - { - DropRoleStmt *n = makeNode(DropRoleStmt); - n->missing_ok = TRUE; - n->roles = $5; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * Manipulate a schema - * - *****************************************************************************/ - -CreateSchemaStmt: - CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList - { - CreateSchemaStmt *n = makeNode(CreateSchemaStmt); - /* One can omit the schema name or the authorization id. */ - if ($3 != NULL) - n->schemaname = $3; - else - n->schemaname = $5; - n->authid = $5; - n->schemaElts = $6; - $$ = (Node *)n; - } - | CREATE SCHEMA ColId OptSchemaEltList - { - CreateSchemaStmt *n = makeNode(CreateSchemaStmt); - /* ...but not both */ - n->schemaname = $3; - n->authid = NULL; - n->schemaElts = $4; - $$ = (Node *)n; - } - ; - -OptSchemaName: - ColId { $$ = $1; } - | /* EMPTY */ { $$ = NULL; } - ; - -OptSchemaEltList: - OptSchemaEltList schema_stmt { $$ = lappend($1, $2); } - | /* EMPTY */ { $$ = NIL; } - ; - -/* - * schema_stmt are the ones that can show up inside a CREATE SCHEMA - * statement (in addition to by themselves). - */ -schema_stmt: - CreateStmt - | IndexStmt - | CreateSeqStmt - | CreateTrigStmt - | GrantStmt - | ViewStmt - ; - - -/***************************************************************************** - * - * Set PG internal variable - * SET name TO 'var_value' - * Include SQL92 syntax (thomas 1997-10-22): - * SET TIME ZONE 'var_value' - * - *****************************************************************************/ - -VariableSetStmt: - SET set_rest - { - VariableSetStmt *n = $2; - n->is_local = false; - $$ = (Node *) n; - } - | SET LOCAL set_rest - { - VariableSetStmt *n = $3; - n->is_local = true; - $$ = (Node *) n; - } - | SET SESSION set_rest - { - VariableSetStmt *n = $3; - n->is_local = false; - $$ = (Node *) n; - } - ; - -set_rest: /* Generic SET syntaxes: */ - var_name TO var_list - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = $1; - n->args = $3; - $$ = n; - } - | var_name '=' var_list - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = $1; - n->args = $3; - $$ = n; - } - | var_name TO DEFAULT - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_DEFAULT; - n->name = $1; - $$ = n; - } - | var_name '=' DEFAULT - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_DEFAULT; - n->name = $1; - $$ = n; - } - | var_name FROM CURRENT_P - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_CURRENT; - n->name = $1; - $$ = n; - } - /* Special syntaxes mandated by SQL standard: */ - | TIME ZONE zone_value - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = "timezone"; - if ($3 != NULL) - n->args = list_make1($3); - else - n->kind = VAR_SET_DEFAULT; - $$ = n; - } - | TRANSACTION transaction_mode_list - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_MULTI; - n->name = "TRANSACTION"; - n->args = $2; - $$ = n; - } - | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_MULTI; - n->name = "SESSION CHARACTERISTICS"; - n->args = $5; - $$ = n; - } - | CATALOG_P Sconst - { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("current database cannot be changed"), - parser_errposition(@2))); - $$ = NULL; /*not reached*/ - } - | SCHEMA Sconst - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = "search_path"; - n->args = list_make1(makeStringConst($2, @2)); - $$ = n; - } - | NAMES opt_encoding - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = "client_encoding"; - if ($2 != NULL) - n->args = list_make1(makeStringConst($2, @2)); - else - n->kind = VAR_SET_DEFAULT; - $$ = n; - } - | ROLE ColId_or_Sconst - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = "role"; - n->args = list_make1(makeStringConst($2, @2)); - $$ = n; - } - | SESSION AUTHORIZATION ColId_or_Sconst - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = "session_authorization"; - n->args = list_make1(makeStringConst($3, @3)); - $$ = n; - } - | SESSION AUTHORIZATION DEFAULT - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_DEFAULT; - n->name = "session_authorization"; - $$ = n; - } - | XML_P OPTION document_or_content - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_SET_VALUE; - n->name = "xmloption"; - n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3)); - $$ = n; - } - ; - -var_name: ColId { $$ = $1; } - | var_name '.' ColId - { - $$ = palloc(strlen($1) + strlen($3) + 2); - sprintf($$, "%s.%s", $1, $3); - } - ; - -var_list: var_value { $$ = list_make1($1); } - | var_list ',' var_value { $$ = lappend($1, $3); } - ; - -var_value: opt_boolean_or_string - { $$ = makeStringConst($1, @1); } - | NumericOnly - { $$ = makeAConst($1, @1); } - ; - -iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; } - | READ COMMITTED { $$ = "read committed"; } - | REPEATABLE READ { $$ = "repeatable read"; } - | SERIALIZABLE { $$ = "serializable"; } - ; - -opt_boolean_or_string: - TRUE_P { $$ = "true"; } - | FALSE_P { $$ = "false"; } - | ON { $$ = "on"; } - /* - * OFF is also accepted as a boolean value, but is handled - * by the ColId rule below. The action for booleans and strings - * is the same, so we don't need to distinguish them here. - */ - | ColId_or_Sconst { $$ = $1; } - ; - -/* Timezone values can be: - * - a string such as 'pst8pdt' - * - an identifier such as "pst8pdt" - * - an integer or floating point number - * - a time interval per SQL99 - * ColId gives reduce/reduce errors against ConstInterval and LOCAL, - * so use IDENT (meaning we reject anything that is a key word). - */ -zone_value: - Sconst - { - $$ = makeStringConst($1, @1); - } - | IDENT - { - $$ = makeStringConst($1, @1); - } - | ConstInterval Sconst opt_interval - { - TypeName *t = $1; - if ($3 != NIL) - { - A_Const *n = (A_Const *) linitial($3); - if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("time zone interval must be HOUR or HOUR TO MINUTE"), - parser_errposition(@3))); - } - t->typmods = $3; - $$ = makeStringConstCast($2, @2, t); - } - | ConstInterval '(' Iconst ')' Sconst opt_interval - { - TypeName *t = $1; - if ($6 != NIL) - { - A_Const *n = (A_Const *) linitial($6); - if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("time zone interval must be HOUR or HOUR TO MINUTE"), - parser_errposition(@6))); - if (list_length($6) != 1) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("interval precision specified twice"), - parser_errposition(@1))); - t->typmods = lappend($6, makeIntConst($3, @3)); - } - else - t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1), - makeIntConst($3, @3)); - $$ = makeStringConstCast($5, @5, t); - } - | NumericOnly { $$ = makeAConst($1, @1); } - | DEFAULT { $$ = NULL; } - | LOCAL { $$ = NULL; } - ; - -opt_encoding: - Sconst { $$ = $1; } - | DEFAULT { $$ = NULL; } - | /*EMPTY*/ { $$ = NULL; } - ; - -ColId_or_Sconst: - ColId { $$ = $1; } - | Sconst { $$ = $1; } - ; - -VariableResetStmt: - RESET var_name - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_RESET; - n->name = $2; - $$ = (Node *) n; - } - | RESET TIME ZONE - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_RESET; - n->name = "timezone"; - $$ = (Node *) n; - } - | RESET TRANSACTION ISOLATION LEVEL - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_RESET; - n->name = "transaction_isolation"; - $$ = (Node *) n; - } - | RESET SESSION AUTHORIZATION - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_RESET; - n->name = "session_authorization"; - $$ = (Node *) n; - } - | RESET ALL - { - VariableSetStmt *n = makeNode(VariableSetStmt); - n->kind = VAR_RESET_ALL; - $$ = (Node *) n; - } - ; - -/* SetResetClause allows SET or RESET without LOCAL */ -SetResetClause: - SET set_rest { $$ = $2; } - | VariableResetStmt { $$ = (VariableSetStmt *) $1; } - ; - - -VariableShowStmt: - SHOW var_name - { - VariableShowStmt *n = makeNode(VariableShowStmt); - n->name = $2; - $$ = (Node *) n; - } - | SHOW TIME ZONE - { - VariableShowStmt *n = makeNode(VariableShowStmt); - n->name = "timezone"; - $$ = (Node *) n; - } - | SHOW TRANSACTION ISOLATION LEVEL - { - VariableShowStmt *n = makeNode(VariableShowStmt); - n->name = "transaction_isolation"; - $$ = (Node *) n; - } - | SHOW SESSION AUTHORIZATION - { - VariableShowStmt *n = makeNode(VariableShowStmt); - n->name = "session_authorization"; - $$ = (Node *) n; - } - | SHOW ALL - { - VariableShowStmt *n = makeNode(VariableShowStmt); - n->name = "all"; - $$ = (Node *) n; - } - ; - - -ConstraintsSetStmt: - SET CONSTRAINTS constraints_set_list constraints_set_mode - { - ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt); - n->constraints = $3; - n->deferred = $4; - $$ = (Node *) n; - } - ; - -constraints_set_list: - ALL { $$ = NIL; } - | qualified_name_list { $$ = $1; } - ; - -constraints_set_mode: - DEFERRED { $$ = TRUE; } - | IMMEDIATE { $$ = FALSE; } - ; - - -/* - * Checkpoint statement - */ -CheckPointStmt: - CHECKPOINT - { - CheckPointStmt *n = makeNode(CheckPointStmt); - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * DISCARD { ALL | TEMP | PLANS } - * - *****************************************************************************/ - -DiscardStmt: - DISCARD ALL - { - DiscardStmt *n = makeNode(DiscardStmt); - n->target = DISCARD_ALL; - $$ = (Node *) n; - } - | DISCARD TEMP - { - DiscardStmt *n = makeNode(DiscardStmt); - n->target = DISCARD_TEMP; - $$ = (Node *) n; - } - | DISCARD TEMPORARY - { - DiscardStmt *n = makeNode(DiscardStmt); - n->target = DISCARD_TEMP; - $$ = (Node *) n; - } - | DISCARD PLANS - { - DiscardStmt *n = makeNode(DiscardStmt); - n->target = DISCARD_PLANS; - $$ = (Node *) n; - } - ; - - -/***************************************************************************** - * - * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations - * - * Note: we accept all subcommands for each of the four variants, and sort - * out what's really legal at execution time. - *****************************************************************************/ - -AlterTableStmt: - ALTER TABLE relation_expr alter_table_cmds - { - AlterTableStmt *n = makeNode(AlterTableStmt); - n->relation = $3; - n->cmds = $4; - n->relkind = OBJECT_TABLE; - $$ = (Node *)n; - } - | ALTER INDEX qualified_name alter_table_cmds - { - AlterTableStmt *n = makeNode(AlterTableStmt); - n->relation = $3; - n->cmds = $4; - n->relkind = OBJECT_INDEX; - $$ = (Node *)n; - } - | ALTER SEQUENCE qualified_name alter_table_cmds - { - AlterTableStmt *n = makeNode(AlterTableStmt); - n->relation = $3; - n->cmds = $4; - n->relkind = OBJECT_SEQUENCE; - $$ = (Node *)n; - } - | ALTER VIEW qualified_name alter_table_cmds - { - AlterTableStmt *n = makeNode(AlterTableStmt); - n->relation = $3; - n->cmds = $4; - n->relkind = OBJECT_VIEW; - $$ = (Node *)n; - } - ; - -alter_table_cmds: - alter_table_cmd { $$ = list_make1($1); } - | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); } - ; - -alter_table_cmd: - /* ALTER TABLE ADD */ - ADD_P columnDef - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_AddColumn; - n->def = $2; - $$ = (Node *)n; - } - /* ALTER TABLE ADD COLUMN */ - | ADD_P COLUMN columnDef - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_AddColumn; - n->def = $3; - $$ = (Node *)n; - } - /* ALTER TABLE ALTER [COLUMN] {SET DEFAULT |DROP DEFAULT} */ - | ALTER opt_column ColId alter_column_default - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_ColumnDefault; - n->name = $3; - n->def = $4; - $$ = (Node *)n; - } - /* ALTER TABLE ALTER [COLUMN] DROP NOT NULL */ - | ALTER opt_column ColId DROP NOT NULL_P - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropNotNull; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE ALTER [COLUMN] SET NOT NULL */ - | ALTER opt_column ColId SET NOT NULL_P - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_SetNotNull; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE ALTER [COLUMN] SET STATISTICS */ - | ALTER opt_column ColId SET STATISTICS SignedIconst - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_SetStatistics; - n->name = $3; - n->def = (Node *) makeInteger($6); - $$ = (Node *)n; - } - /* ALTER TABLE ALTER [COLUMN] SET ( column_parameter = value [, ... ] ) */ - | ALTER opt_column ColId SET reloptions - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_SetOptions; - n->name = $3; - n->def = (Node *) $5; - $$ = (Node *)n; - } - /* ALTER TABLE ALTER [COLUMN] SET ( column_parameter = value [, ... ] ) */ - | ALTER opt_column ColId RESET reloptions - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_ResetOptions; - n->name = $3; - n->def = (Node *) $5; - $$ = (Node *)n; - } - /* ALTER TABLE ALTER [COLUMN] SET STORAGE */ - | ALTER opt_column ColId SET STORAGE ColId - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_SetStorage; - n->name = $3; - n->def = (Node *) makeString($6); - $$ = (Node *)n; - } - /* ALTER TABLE DROP [COLUMN] IF EXISTS [RESTRICT|CASCADE] */ - | DROP opt_column IF_P EXISTS ColId opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropColumn; - n->name = $5; - n->behavior = $6; - n->missing_ok = TRUE; - $$ = (Node *)n; - } - /* ALTER TABLE DROP [COLUMN] [RESTRICT|CASCADE] */ - | DROP opt_column ColId opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropColumn; - n->name = $3; - n->behavior = $4; - n->missing_ok = FALSE; - $$ = (Node *)n; - } - /* - * ALTER TABLE ALTER [COLUMN] [SET DATA] TYPE - * [ USING ] - */ - | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using - { - AlterTableCmd *n = makeNode(AlterTableCmd); - ColumnDef *def = makeNode(ColumnDef); - n->subtype = AT_AlterColumnType; - n->name = $3; - n->def = (Node *) def; - /* We only use these three fields of the ColumnDef node */ - def->typeName = $6; - def->collClause = (CollateClause *) $7; - def->raw_default = $8; - $$ = (Node *)n; - } - /* ALTER TABLE ADD CONSTRAINT ... */ - | ADD_P TableConstraint - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_AddConstraint; - n->def = $2; - $$ = (Node *)n; - } - /* ALTER TABLE VALIDATE CONSTRAINT ... */ - | VALIDATE CONSTRAINT name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_ValidateConstraint; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE DROP CONSTRAINT IF EXISTS [RESTRICT|CASCADE] */ - | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropConstraint; - n->name = $5; - n->behavior = $6; - n->missing_ok = TRUE; - $$ = (Node *)n; - } - /* ALTER TABLE DROP CONSTRAINT [RESTRICT|CASCADE] */ - | DROP CONSTRAINT name opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropConstraint; - n->name = $3; - n->behavior = $4; - n->missing_ok = FALSE; - $$ = (Node *)n; - } - /* ALTER TABLE SET WITH OIDS */ - | SET WITH OIDS - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_AddOids; - $$ = (Node *)n; - } - /* ALTER TABLE SET WITHOUT OIDS */ - | SET WITHOUT OIDS - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropOids; - $$ = (Node *)n; - } - /* ALTER TABLE CLUSTER ON */ - | CLUSTER ON name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_ClusterOn; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE SET WITHOUT CLUSTER */ - | SET WITHOUT CLUSTER - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropCluster; - n->name = NULL; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE TRIGGER */ - | ENABLE_P TRIGGER name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableTrig; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE ALWAYS TRIGGER */ - | ENABLE_P ALWAYS TRIGGER name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableAlwaysTrig; - n->name = $4; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE REPLICA TRIGGER */ - | ENABLE_P REPLICA TRIGGER name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableReplicaTrig; - n->name = $4; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE TRIGGER ALL */ - | ENABLE_P TRIGGER ALL - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableTrigAll; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE TRIGGER USER */ - | ENABLE_P TRIGGER USER - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableTrigUser; - $$ = (Node *)n; - } - /* ALTER TABLE DISABLE TRIGGER */ - | DISABLE_P TRIGGER name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DisableTrig; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE DISABLE TRIGGER ALL */ - | DISABLE_P TRIGGER ALL - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DisableTrigAll; - $$ = (Node *)n; - } - /* ALTER TABLE DISABLE TRIGGER USER */ - | DISABLE_P TRIGGER USER - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DisableTrigUser; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE RULE */ - | ENABLE_P RULE name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableRule; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE ALWAYS RULE */ - | ENABLE_P ALWAYS RULE name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableAlwaysRule; - n->name = $4; - $$ = (Node *)n; - } - /* ALTER TABLE ENABLE REPLICA RULE */ - | ENABLE_P REPLICA RULE name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_EnableReplicaRule; - n->name = $4; - $$ = (Node *)n; - } - /* ALTER TABLE DISABLE RULE */ - | DISABLE_P RULE name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DisableRule; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE INHERIT */ - | INHERIT qualified_name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_AddInherit; - n->def = (Node *) $2; - $$ = (Node *)n; - } - /* ALTER TABLE NO INHERIT */ - | NO INHERIT qualified_name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropInherit; - n->def = (Node *) $3; - $$ = (Node *)n; - } - /* ALTER TABLE OF */ - | OF any_name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - TypeName *def = makeTypeNameFromNameList($2); - def->location = @2; - n->subtype = AT_AddOf; - n->def = (Node *) def; - $$ = (Node *)n; - } - /* ALTER TABLE NOT OF */ - | NOT OF - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropOf; - $$ = (Node *)n; - } - /* ALTER TABLE OWNER TO RoleId */ - | OWNER TO RoleId - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_ChangeOwner; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE SET TABLESPACE */ - | SET TABLESPACE name - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_SetTableSpace; - n->name = $3; - $$ = (Node *)n; - } - /* ALTER TABLE SET (...) */ - | SET reloptions - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_SetRelOptions; - n->def = (Node *)$2; - $$ = (Node *)n; - } - /* ALTER TABLE RESET (...) */ - | RESET reloptions - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_ResetRelOptions; - n->def = (Node *)$2; - $$ = (Node *)n; - } - | alter_generic_options - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_GenericOptions; - n->def = (Node *)$1; - $$ = (Node *) n; - } - ; - -alter_column_default: - SET DEFAULT a_expr { $$ = $3; } - | DROP DEFAULT { $$ = NULL; } - ; - -opt_drop_behavior: - CASCADE { $$ = DROP_CASCADE; } - | RESTRICT { $$ = DROP_RESTRICT; } - | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ } - ; - opt_collate_clause: COLLATE any_name { @@ -2015,2753 +515,6 @@ opt_collate_clause: | /* EMPTY */ { $$ = NULL; } ; -alter_using: - USING a_expr { $$ = $2; } - | /* EMPTY */ { $$ = NULL; } - ; - -reloptions: - '(' reloption_list ')' { $$ = $2; } - ; - -opt_reloptions: WITH reloptions { $$ = $2; } - | /* EMPTY */ { $$ = NIL; } - ; - -reloption_list: - reloption_elem { $$ = list_make1($1); } - | reloption_list ',' reloption_elem { $$ = lappend($1, $3); } - ; - -/* This should match def_elem and also allow qualified names */ -reloption_elem: - ColLabel '=' def_arg - { - $$ = makeDefElem($1, (Node *) $3); - } - | ColLabel - { - $$ = makeDefElem($1, NULL); - } - | ColLabel '.' ColLabel '=' def_arg - { - $$ = makeDefElemExtended($1, $3, (Node *) $5, - DEFELEM_UNSPEC); - } - | ColLabel '.' ColLabel - { - $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC); - } - ; - - -/***************************************************************************** - * - * ALTER TYPE - * - * really variants of the ALTER TABLE subcommands with different spellings - *****************************************************************************/ - -AlterCompositeTypeStmt: - ALTER TYPE_P any_name alter_type_cmds - { - AlterTableStmt *n = makeNode(AlterTableStmt); - - /* can't use qualified_name, sigh */ - n->relation = makeRangeVarFromAnyName($3, @3, yyscanner); - n->cmds = $4; - n->relkind = OBJECT_TYPE; - $$ = (Node *)n; - } - ; - -alter_type_cmds: - alter_type_cmd { $$ = list_make1($1); } - | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); } - ; - -alter_type_cmd: - /* ALTER TYPE ADD ATTRIBUTE [RESTRICT|CASCADE] */ - ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_AddColumn; - n->def = $3; - n->behavior = $4; - $$ = (Node *)n; - } - /* ALTER TYPE DROP ATTRIBUTE IF EXISTS [RESTRICT|CASCADE] */ - | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropColumn; - n->name = $5; - n->behavior = $6; - n->missing_ok = TRUE; - $$ = (Node *)n; - } - /* ALTER TYPE DROP ATTRIBUTE [RESTRICT|CASCADE] */ - | DROP ATTRIBUTE ColId opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_DropColumn; - n->name = $3; - n->behavior = $4; - n->missing_ok = FALSE; - $$ = (Node *)n; - } - /* ALTER TYPE ALTER ATTRIBUTE [SET DATA] TYPE [RESTRICT|CASCADE] */ - | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior - { - AlterTableCmd *n = makeNode(AlterTableCmd); - ColumnDef *def = makeNode(ColumnDef); - n->subtype = AT_AlterColumnType; - n->name = $3; - n->def = (Node *) def; - n->behavior = $8; - /* We only use these three fields of the ColumnDef node */ - def->typeName = $6; - def->collClause = (CollateClause *) $7; - def->raw_default = NULL; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * QUERY : - * close - * - *****************************************************************************/ - -ClosePortalStmt: - CLOSE cursor_name - { - ClosePortalStmt *n = makeNode(ClosePortalStmt); - n->portalname = $2; - $$ = (Node *)n; - } - | CLOSE ALL - { - ClosePortalStmt *n = makeNode(ClosePortalStmt); - n->portalname = NULL; - $$ = (Node *)n; - } - ; - - -/***************************************************************************** - * - * QUERY : - * COPY relname [(columnList)] FROM/TO file [WITH] [(options)] - * COPY ( SELECT ... ) TO file [WITH] [(options)] - * - * In the preferred syntax the options are comma-separated - * and use generic identifiers instead of keywords. The pre-9.0 - * syntax had a hard-wired, space-separated set of options. - * - * Really old syntax, from versions 7.2 and prior: - * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file - * [ [ USING ] DELIMITERS 'delimiter' ] ] - * [ WITH NULL AS 'null string' ] - * This option placement is not supported with COPY (SELECT...). - * - *****************************************************************************/ - -CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids - copy_from copy_file_name copy_delimiter opt_with copy_options - { - CopyStmt *n = makeNode(CopyStmt); - n->relation = $3; - n->query = NULL; - n->attlist = $4; - n->is_from = $6; - n->filename = $7; - - n->options = NIL; - /* Concatenate user-supplied flags */ - if ($2) - n->options = lappend(n->options, $2); - if ($5) - n->options = lappend(n->options, $5); - if ($8) - n->options = lappend(n->options, $8); - if ($10) - n->options = list_concat(n->options, $10); - $$ = (Node *)n; - } - | COPY select_with_parens TO copy_file_name opt_with copy_options - { - CopyStmt *n = makeNode(CopyStmt); - n->relation = NULL; - n->query = $2; - n->attlist = NIL; - n->is_from = false; - n->filename = $4; - n->options = $6; - $$ = (Node *)n; - } - ; - -copy_from: - FROM { $$ = TRUE; } - | TO { $$ = FALSE; } - ; - -/* - * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is - * used depends on the direction. (It really doesn't make sense to copy from - * stdout. We silently correct the "typo".) - AY 9/94 - */ -copy_file_name: - Sconst { $$ = $1; } - | STDIN { $$ = NULL; } - | STDOUT { $$ = NULL; } - ; - -copy_options: copy_opt_list { $$ = $1; } - | '(' copy_generic_opt_list ')' { $$ = $2; } - ; - -/* old COPY option syntax */ -copy_opt_list: - copy_opt_list copy_opt_item { $$ = lappend($1, $2); } - | /* EMPTY */ { $$ = NIL; } - ; - -copy_opt_item: - BINARY - { - $$ = makeDefElem("format", (Node *)makeString("binary")); - } - | OIDS - { - $$ = makeDefElem("oids", (Node *)makeInteger(TRUE)); - } - | DELIMITER opt_as Sconst - { - $$ = makeDefElem("delimiter", (Node *)makeString($3)); - } - | NULL_P opt_as Sconst - { - $$ = makeDefElem("null", (Node *)makeString($3)); - } - | CSV - { - $$ = makeDefElem("format", (Node *)makeString("csv")); - } - | HEADER_P - { - $$ = makeDefElem("header", (Node *)makeInteger(TRUE)); - } - | QUOTE opt_as Sconst - { - $$ = makeDefElem("quote", (Node *)makeString($3)); - } - | ESCAPE opt_as Sconst - { - $$ = makeDefElem("escape", (Node *)makeString($3)); - } - | FORCE QUOTE columnList - { - $$ = makeDefElem("force_quote", (Node *)$3); - } - | FORCE QUOTE '*' - { - $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star)); - } - | FORCE NOT NULL_P columnList - { - $$ = makeDefElem("force_not_null", (Node *)$4); - } - | ENCODING Sconst - { - $$ = makeDefElem("encoding", (Node *)makeString($2)); - } - ; - -/* The following exist for backward compatibility with very old versions */ - -opt_binary: - BINARY - { - $$ = makeDefElem("format", (Node *)makeString("binary")); - } - | /*EMPTY*/ { $$ = NULL; } - ; - -opt_oids: - WITH OIDS - { - $$ = makeDefElem("oids", (Node *)makeInteger(TRUE)); - } - | /*EMPTY*/ { $$ = NULL; } - ; - -copy_delimiter: - opt_using DELIMITERS Sconst - { - $$ = makeDefElem("delimiter", (Node *)makeString($3)); - } - | /*EMPTY*/ { $$ = NULL; } - ; - -opt_using: - USING {} - | /*EMPTY*/ {} - ; - -/* new COPY option syntax */ -copy_generic_opt_list: - copy_generic_opt_elem - { - $$ = list_make1($1); - } - | copy_generic_opt_list ',' copy_generic_opt_elem - { - $$ = lappend($1, $3); - } - ; - -copy_generic_opt_elem: - ColLabel copy_generic_opt_arg - { - $$ = makeDefElem($1, $2); - } - ; - -copy_generic_opt_arg: - opt_boolean_or_string { $$ = (Node *) makeString($1); } - | NumericOnly { $$ = (Node *) $1; } - | '*' { $$ = (Node *) makeNode(A_Star); } - | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; } - | /* EMPTY */ { $$ = NULL; } - ; - -copy_generic_opt_arg_list: - copy_generic_opt_arg_list_item - { - $$ = list_make1($1); - } - | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item - { - $$ = lappend($1, $3); - } - ; - -/* beware of emitting non-string list elements here; see commands/define.c */ -copy_generic_opt_arg_list_item: - opt_boolean_or_string { $$ = (Node *) makeString($1); } - ; - - -/***************************************************************************** - * - * QUERY : - * CREATE TABLE relname - * - *****************************************************************************/ - -CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')' - OptInherit OptWith OnCommitOption OptTableSpace - { - CreateStmt *n = makeNode(CreateStmt); - $4->relpersistence = $2; - n->relation = $4; - n->tableElts = $6; - n->inhRelations = $8; - n->constraints = NIL; - n->options = $9; - n->oncommit = $10; - n->tablespacename = $11; - n->if_not_exists = false; - $$ = (Node *)n; - } - | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '(' - OptTableElementList ')' OptInherit OptWith OnCommitOption - OptTableSpace - { - CreateStmt *n = makeNode(CreateStmt); - $7->relpersistence = $2; - n->relation = $7; - n->tableElts = $9; - n->inhRelations = $11; - n->constraints = NIL; - n->options = $12; - n->oncommit = $13; - n->tablespacename = $14; - n->if_not_exists = true; - $$ = (Node *)n; - } - | CREATE OptTemp TABLE qualified_name OF any_name - OptTypedTableElementList OptWith OnCommitOption OptTableSpace - { - CreateStmt *n = makeNode(CreateStmt); - $4->relpersistence = $2; - n->relation = $4; - n->tableElts = $7; - n->ofTypename = makeTypeNameFromNameList($6); - n->ofTypename->location = @6; - n->constraints = NIL; - n->options = $8; - n->oncommit = $9; - n->tablespacename = $10; - n->if_not_exists = false; - $$ = (Node *)n; - } - | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name - OptTypedTableElementList OptWith OnCommitOption OptTableSpace - { - CreateStmt *n = makeNode(CreateStmt); - $7->relpersistence = $2; - n->relation = $7; - n->tableElts = $10; - n->ofTypename = makeTypeNameFromNameList($9); - n->ofTypename->location = @9; - n->constraints = NIL; - n->options = $11; - n->oncommit = $12; - n->tablespacename = $13; - n->if_not_exists = true; - $$ = (Node *)n; - } - ; - -/* - * Redundancy here is needed to avoid shift/reduce conflicts, - * since TEMP is not a reserved word. See also OptTempTableName. - * - * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules - * the LOCAL keyword is really meaningless. - */ -OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; } - | TEMP { $$ = RELPERSISTENCE_TEMP; } - | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; } - | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; } - | GLOBAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; } - | GLOBAL TEMP { $$ = RELPERSISTENCE_TEMP; } - | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; } - | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; } - ; - -OptTableElementList: - TableElementList { $$ = $1; } - | /*EMPTY*/ { $$ = NIL; } - ; - -OptTypedTableElementList: - '(' TypedTableElementList ')' { $$ = $2; } - | /*EMPTY*/ { $$ = NIL; } - ; - -TableElementList: - TableElement - { - $$ = list_make1($1); - } - | TableElementList ',' TableElement - { - $$ = lappend($1, $3); - } - ; - -TypedTableElementList: - TypedTableElement - { - $$ = list_make1($1); - } - | TypedTableElementList ',' TypedTableElement - { - $$ = lappend($1, $3); - } - ; - -TableElement: - columnDef { $$ = $1; } - | TableLikeClause { $$ = $1; } - | TableConstraint { $$ = $1; } - ; - -TypedTableElement: - columnOptions { $$ = $1; } - | TableConstraint { $$ = $1; } - ; - -columnDef: ColId Typename ColQualList - { - ColumnDef *n = makeNode(ColumnDef); - n->colname = $1; - n->typeName = $2; - n->inhcount = 0; - n->is_local = true; - n->is_not_null = false; - n->is_from_type = false; - n->storage = 0; - n->raw_default = NULL; - n->cooked_default = NULL; - n->collOid = InvalidOid; - SplitColQualList($3, &n->constraints, &n->collClause, - yyscanner); - $$ = (Node *)n; - } - ; - -columnOptions: ColId WITH OPTIONS ColQualList - { - ColumnDef *n = makeNode(ColumnDef); - n->colname = $1; - n->typeName = NULL; - n->inhcount = 0; - n->is_local = true; - n->is_not_null = false; - n->is_from_type = false; - n->storage = 0; - n->raw_default = NULL; - n->cooked_default = NULL; - n->collOid = InvalidOid; - SplitColQualList($4, &n->constraints, &n->collClause, - yyscanner); - $$ = (Node *)n; - } - ; - -ColQualList: - ColQualList ColConstraint { $$ = lappend($1, $2); } - | /*EMPTY*/ { $$ = NIL; } - ; - -ColConstraint: - CONSTRAINT name ColConstraintElem - { - Constraint *n = (Constraint *) $3; - Assert(IsA(n, Constraint)); - n->conname = $2; - n->location = @1; - $$ = (Node *) n; - } - | ColConstraintElem { $$ = $1; } - | ConstraintAttr { $$ = $1; } - | COLLATE any_name - { - /* - * Note: the CollateClause is momentarily included in - * the list built by ColQualList, but we split it out - * again in SplitColQualList. - */ - CollateClause *n = makeNode(CollateClause); - n->arg = NULL; - n->collname = $2; - n->location = @1; - $$ = (Node *) n; - } - ; - -/* DEFAULT NULL is already the default for Postgres. - * But define it here and carry it forward into the system - * to make it explicit. - * - thomas 1998-09-13 - * - * WITH NULL and NULL are not SQL92-standard syntax elements, - * so leave them out. Use DEFAULT NULL to explicitly indicate - * that a column may have that value. WITH NULL leads to - * shift/reduce conflicts with WITH TIME ZONE anyway. - * - thomas 1999-01-08 - * - * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce - * conflict on NOT (since NOT might start a subsequent NOT NULL constraint, - * or be part of a_expr NOT LIKE or similar constructs). - */ -ColConstraintElem: - NOT NULL_P - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_NOTNULL; - n->location = @1; - $$ = (Node *)n; - } - | NULL_P - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_NULL; - n->location = @1; - $$ = (Node *)n; - } - | UNIQUE opt_definition OptConsTableSpace - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_UNIQUE; - n->location = @1; - n->keys = NULL; - n->options = $2; - n->indexname = NULL; - n->indexspace = $3; - $$ = (Node *)n; - } - | PRIMARY KEY opt_definition OptConsTableSpace - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_PRIMARY; - n->location = @1; - n->keys = NULL; - n->options = $3; - n->indexname = NULL; - n->indexspace = $4; - $$ = (Node *)n; - } - | CHECK '(' a_expr ')' - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_CHECK; - n->location = @1; - n->raw_expr = $3; - n->cooked_expr = NULL; - $$ = (Node *)n; - } - | DEFAULT b_expr - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_DEFAULT; - n->location = @1; - n->raw_expr = $2; - n->cooked_expr = NULL; - $$ = (Node *)n; - } - | REFERENCES qualified_name opt_column_list key_match key_actions - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_FOREIGN; - n->location = @1; - n->pktable = $2; - n->fk_attrs = NIL; - n->pk_attrs = $3; - n->fk_matchtype = $4; - n->fk_upd_action = (char) ($5 >> 8); - n->fk_del_action = (char) ($5 & 0xFF); - n->skip_validation = FALSE; - n->initially_valid = true; - $$ = (Node *)n; - } - ; - -/* - * ConstraintAttr represents constraint attributes, which we parse as if - * they were independent constraint clauses, in order to avoid shift/reduce - * conflicts (since NOT might start either an independent NOT NULL clause - * or an attribute). parse_utilcmd.c is responsible for attaching the - * attribute information to the preceding "real" constraint node, and for - * complaining if attribute clauses appear in the wrong place or wrong - * combinations. - * - * See also ConstraintAttributeSpec, which can be used in places where - * there is no parsing conflict. - */ -ConstraintAttr: - DEFERRABLE - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_ATTR_DEFERRABLE; - n->location = @1; - $$ = (Node *)n; - } - | NOT DEFERRABLE - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_ATTR_NOT_DEFERRABLE; - n->location = @1; - $$ = (Node *)n; - } - | INITIALLY DEFERRED - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_ATTR_DEFERRED; - n->location = @1; - $$ = (Node *)n; - } - | INITIALLY IMMEDIATE - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_ATTR_IMMEDIATE; - n->location = @1; - $$ = (Node *)n; - } - ; - - -/* - * SQL99 supports wholesale borrowing of a table definition via the LIKE clause. - * This seems to be a poor man's inheritance capability, with the resulting - * tables completely decoupled except for the original commonality in definitions. - * - * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension - * which is a part of SQL:2003. - */ -TableLikeClause: - LIKE qualified_name TableLikeOptionList - { - InhRelation *n = makeNode(InhRelation); - n->relation = $2; - n->options = $3; - $$ = (Node *)n; - } - ; - -TableLikeOptionList: - TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; } - | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; } - | /* EMPTY */ { $$ = 0; } - ; - -TableLikeOption: - DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; } - | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; } - | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; } - | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; } - | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; } - | ALL { $$ = CREATE_TABLE_LIKE_ALL; } - ; - - -/* ConstraintElem specifies constraint syntax which is not embedded into - * a column definition. ColConstraintElem specifies the embedded form. - * - thomas 1997-12-03 - */ -TableConstraint: - CONSTRAINT name ConstraintElem - { - Constraint *n = (Constraint *) $3; - Assert(IsA(n, Constraint)); - n->conname = $2; - n->location = @1; - $$ = (Node *) n; - } - | ConstraintElem { $$ = $1; } - ; - -ConstraintElem: - CHECK '(' a_expr ')' ConstraintAttributeSpec - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_CHECK; - n->location = @1; - n->raw_expr = $3; - n->cooked_expr = NULL; - if ($5 != 0) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("CHECK constraints cannot be deferred"), - parser_errposition(@5))); - $$ = (Node *)n; - } - | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace - ConstraintAttributeSpec - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_UNIQUE; - n->location = @1; - n->keys = $3; - n->options = $5; - n->indexname = NULL; - n->indexspace = $6; - n->deferrable = ($7 & 1) != 0; - n->initdeferred = ($7 & 2) != 0; - $$ = (Node *)n; - } - | UNIQUE ExistingIndex ConstraintAttributeSpec - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_UNIQUE; - n->location = @1; - n->keys = NIL; - n->options = NIL; - n->indexname = $2; - n->indexspace = NULL; - n->deferrable = ($3 & 1) != 0; - n->initdeferred = ($3 & 2) != 0; - $$ = (Node *)n; - } - | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace - ConstraintAttributeSpec - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_PRIMARY; - n->location = @1; - n->keys = $4; - n->options = $6; - n->indexname = NULL; - n->indexspace = $7; - n->deferrable = ($8 & 1) != 0; - n->initdeferred = ($8 & 2) != 0; - $$ = (Node *)n; - } - | PRIMARY KEY ExistingIndex ConstraintAttributeSpec - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_PRIMARY; - n->location = @1; - n->keys = NIL; - n->options = NIL; - n->indexname = $3; - n->indexspace = NULL; - n->deferrable = ($4 & 1) != 0; - n->initdeferred = ($4 & 2) != 0; - $$ = (Node *)n; - } - | EXCLUDE access_method_clause '(' ExclusionConstraintList ')' - opt_definition OptConsTableSpace ExclusionWhereClause - ConstraintAttributeSpec - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_EXCLUSION; - n->location = @1; - n->access_method = $2; - n->exclusions = $4; - n->options = $6; - n->indexname = NULL; - n->indexspace = $7; - n->where_clause = $8; - n->deferrable = ($9 & 1) != 0; - n->initdeferred = ($9 & 2) != 0; - $$ = (Node *)n; - } - | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name - opt_column_list key_match key_actions ConstraintAttributeSpec - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_FOREIGN; - n->location = @1; - n->pktable = $7; - n->fk_attrs = $4; - n->pk_attrs = $8; - n->fk_matchtype = $9; - n->fk_upd_action = (char) ($10 >> 8); - n->fk_del_action = (char) ($10 & 0xFF); - n->deferrable = ($11 & 1) != 0; - n->initdeferred = ($11 & 2) != 0; - n->skip_validation = false; - n->initially_valid = true; - $$ = (Node *)n; - } - | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name - opt_column_list key_match key_actions - NOT VALID - { - Constraint *n = makeNode(Constraint); - n->contype = CONSTR_FOREIGN; - n->location = @1; - n->pktable = $7; - n->fk_attrs = $4; - n->pk_attrs = $8; - n->fk_matchtype = $9; - n->fk_upd_action = (char) ($10 >> 8); - n->fk_del_action = (char) ($10 & 0xFF); - n->skip_validation = true; - n->initially_valid = false; - $$ = (Node *)n; - } - ; - -opt_column_list: - '(' columnList ')' { $$ = $2; } - | /*EMPTY*/ { $$ = NIL; } - ; - -columnList: - columnElem { $$ = list_make1($1); } - | columnList ',' columnElem { $$ = lappend($1, $3); } - ; - -columnElem: ColId - { - $$ = (Node *) makeString($1); - } - ; - -key_match: MATCH FULL - { - $$ = FKCONSTR_MATCH_FULL; - } - | MATCH PARTIAL - { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("MATCH PARTIAL not yet implemented"), - parser_errposition(@1))); - $$ = FKCONSTR_MATCH_PARTIAL; - } - | MATCH SIMPLE - { - $$ = FKCONSTR_MATCH_UNSPECIFIED; - } - | /*EMPTY*/ - { - $$ = FKCONSTR_MATCH_UNSPECIFIED; - } - ; - -ExclusionConstraintList: - ExclusionConstraintElem { $$ = list_make1($1); } - | ExclusionConstraintList ',' ExclusionConstraintElem - { $$ = lappend($1, $3); } - ; - -ExclusionConstraintElem: index_elem WITH any_operator - { - $$ = list_make2($1, $3); - } - /* allow OPERATOR() decoration for the benefit of ruleutils.c */ - | index_elem WITH OPERATOR '(' any_operator ')' - { - $$ = list_make2($1, $5); - } - ; - -ExclusionWhereClause: - WHERE '(' a_expr ')' { $$ = $3; } - | /*EMPTY*/ { $$ = NULL; } - ; - -/* - * We combine the update and delete actions into one value temporarily - * for simplicity of parsing, and then break them down again in the - * calling production. update is in the left 8 bits, delete in the right. - * Note that NOACTION is the default. - */ -key_actions: - key_update - { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); } - | key_delete - { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); } - | key_update key_delete - { $$ = ($1 << 8) | ($2 & 0xFF); } - | key_delete key_update - { $$ = ($2 << 8) | ($1 & 0xFF); } - | /*EMPTY*/ - { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); } - ; - -key_update: ON UPDATE key_action { $$ = $3; } - ; - -key_delete: ON DELETE_P key_action { $$ = $3; } - ; - -key_action: - NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; } - | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; } - | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; } - | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; } - | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; } - ; - -OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; } - | /*EMPTY*/ { $$ = NIL; } - ; - -/* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */ -OptWith: - WITH reloptions { $$ = $2; } - | WITH OIDS { $$ = list_make1(defWithOids(true)); } - | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); } - | /*EMPTY*/ { $$ = NIL; } - ; - -OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; } - | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; } - | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; } - | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; } - ; - -OptTableSpace: TABLESPACE name { $$ = $2; } - | /*EMPTY*/ { $$ = NULL; } - ; - -OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; } - | /*EMPTY*/ { $$ = NULL; } - ; - -ExistingIndex: USING INDEX index_name { $$ = $3; } - ; - - -/* - * Note: CREATE TABLE ... AS SELECT ... is just another spelling for - * SELECT ... INTO. - */ - -CreateAsStmt: - CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data - { - /* - * When the SelectStmt is a set-operation tree, we must - * stuff the INTO information into the leftmost component - * Select, because that's where analyze.c will expect - * to find it. Similarly, the output column names must - * be attached to that Select's target list. - */ - SelectStmt *n = findLeftmostSelect((SelectStmt *) $6); - if (n->intoClause != NULL) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("CREATE TABLE AS cannot specify INTO"), - parser_errposition(exprLocation((Node *) n->intoClause)))); - $4->rel->relpersistence = $2; - n->intoClause = $4; - /* Implement WITH NO DATA by forcing top-level LIMIT 0 */ - if (!$7) - ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1); - $$ = $6; - } - ; - -create_as_target: - qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace - { - $$ = makeNode(IntoClause); - $$->rel = $1; - $$->colNames = $2; - $$->options = $3; - $$->onCommit = $4; - $$->tableSpaceName = $5; - } - ; - -OptCreateAs: - '(' CreateAsList ')' { $$ = $2; } - | /*EMPTY*/ { $$ = NIL; } - ; - -CreateAsList: - CreateAsElement { $$ = list_make1($1); } - | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); } - ; - -CreateAsElement: - ColId - { - ColumnDef *n = makeNode(ColumnDef); - n->colname = $1; - n->typeName = NULL; - n->inhcount = 0; - n->is_local = true; - n->is_not_null = false; - n->is_from_type = false; - n->storage = 0; - n->raw_default = NULL; - n->cooked_default = NULL; - n->collClause = NULL; - n->collOid = InvalidOid; - n->constraints = NIL; - $$ = (Node *)n; - } - ; - -opt_with_data: - WITH DATA_P { $$ = TRUE; } - | WITH NO DATA_P { $$ = FALSE; } - | /*EMPTY*/ { $$ = TRUE; } - ; - - -/***************************************************************************** - * - * QUERY : - * CREATE SEQUENCE seqname - * ALTER SEQUENCE seqname - * - *****************************************************************************/ - -CreateSeqStmt: - CREATE OptTemp SEQUENCE qualified_name OptSeqOptList - { - CreateSeqStmt *n = makeNode(CreateSeqStmt); - $4->relpersistence = $2; - n->sequence = $4; - n->options = $5; - n->ownerId = InvalidOid; - $$ = (Node *)n; - } - ; - -AlterSeqStmt: - ALTER SEQUENCE qualified_name SeqOptList - { - AlterSeqStmt *n = makeNode(AlterSeqStmt); - n->sequence = $3; - n->options = $4; - $$ = (Node *)n; - } - ; - -OptSeqOptList: SeqOptList { $$ = $1; } - | /*EMPTY*/ { $$ = NIL; } - ; - -SeqOptList: SeqOptElem { $$ = list_make1($1); } - | SeqOptList SeqOptElem { $$ = lappend($1, $2); } - ; - -SeqOptElem: CACHE NumericOnly - { - $$ = makeDefElem("cache", (Node *)$2); - } - | CYCLE - { - $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE)); - } - | NO CYCLE - { - $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE)); - } - | INCREMENT opt_by NumericOnly - { - $$ = makeDefElem("increment", (Node *)$3); - } - | MAXVALUE NumericOnly - { - $$ = makeDefElem("maxvalue", (Node *)$2); - } - | MINVALUE NumericOnly - { - $$ = makeDefElem("minvalue", (Node *)$2); - } - | NO MAXVALUE - { - $$ = makeDefElem("maxvalue", NULL); - } - | NO MINVALUE - { - $$ = makeDefElem("minvalue", NULL); - } - | OWNED BY any_name - { - $$ = makeDefElem("owned_by", (Node *)$3); - } - | START opt_with NumericOnly - { - $$ = makeDefElem("start", (Node *)$3); - } - | RESTART - { - $$ = makeDefElem("restart", NULL); - } - | RESTART opt_with NumericOnly - { - $$ = makeDefElem("restart", (Node *)$3); - } - ; - -opt_by: BY {} - | /* empty */ {} - ; - -NumericOnly: - FCONST { $$ = makeFloat($1); } - | '-' FCONST - { - $$ = makeFloat($2); - doNegateFloat($$); - } - | SignedIconst { $$ = makeInteger($1); } - ; - -NumericOnly_list: NumericOnly { $$ = list_make1($1); } - | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); } - ; - -/***************************************************************************** - * - * QUERIES : - * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ... - * DROP [PROCEDURAL] LANGUAGE ... - * - *****************************************************************************/ - -CreatePLangStmt: - CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst - { - CreatePLangStmt *n = makeNode(CreatePLangStmt); - n->replace = $2; - n->plname = $6; - /* parameters are all to be supplied by system */ - n->plhandler = NIL; - n->plinline = NIL; - n->plvalidator = NIL; - n->pltrusted = false; - $$ = (Node *)n; - } - | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst - HANDLER handler_name opt_inline_handler opt_validator - { - CreatePLangStmt *n = makeNode(CreatePLangStmt); - n->replace = $2; - n->plname = $6; - n->plhandler = $8; - n->plinline = $9; - n->plvalidator = $10; - n->pltrusted = $3; - $$ = (Node *)n; - } - ; - -opt_trusted: - TRUSTED { $$ = TRUE; } - | /*EMPTY*/ { $$ = FALSE; } - ; - -/* This ought to be just func_name, but that causes reduce/reduce conflicts - * (CREATE LANGUAGE is the only place where func_name isn't followed by '('). - * Work around by using simple names, instead. - */ -handler_name: - name { $$ = list_make1(makeString($1)); } - | name attrs { $$ = lcons(makeString($1), $2); } - ; - -opt_inline_handler: - INLINE_P handler_name { $$ = $2; } - | /*EMPTY*/ { $$ = NIL; } - ; - -validator_clause: - VALIDATOR handler_name { $$ = $2; } - | NO VALIDATOR { $$ = NIL; } - ; - -opt_validator: - validator_clause { $$ = $1; } - | /*EMPTY*/ { $$ = NIL; } - ; - -DropPLangStmt: - DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior - { - DropPLangStmt *n = makeNode(DropPLangStmt); - n->plname = $4; - n->behavior = $5; - n->missing_ok = false; - $$ = (Node *)n; - } - | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior - { - DropPLangStmt *n = makeNode(DropPLangStmt); - n->plname = $6; - n->behavior = $7; - n->missing_ok = true; - $$ = (Node *)n; - } - ; - -opt_procedural: - PROCEDURAL {} - | /*EMPTY*/ {} - ; - -/***************************************************************************** - * - * QUERY: - * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/' - * - *****************************************************************************/ - -CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst - { - CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt); - n->tablespacename = $3; - n->owner = $4; - n->location = $6; - $$ = (Node *) n; - } - ; - -OptTableSpaceOwner: OWNER name { $$ = $2; } - | /*EMPTY */ { $$ = NULL; } - ; - -/***************************************************************************** - * - * QUERY : - * DROP TABLESPACE - * - * No need for drop behaviour as we cannot implement dependencies for - * objects in other databases; we can only support RESTRICT. - * - ****************************************************************************/ - -DropTableSpaceStmt: DROP TABLESPACE name - { - DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt); - n->tablespacename = $3; - n->missing_ok = false; - $$ = (Node *) n; - } - | DROP TABLESPACE IF_P EXISTS name - { - DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt); - n->tablespacename = $5; - n->missing_ok = true; - $$ = (Node *) n; - } - ; - -/***************************************************************************** - * - * QUERY: - * CREATE EXTENSION extension - * [ WITH ] [ SCHEMA schema ] [ VERSION version ] [ FROM oldversion ] - * - *****************************************************************************/ - -CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list - { - CreateExtensionStmt *n = makeNode(CreateExtensionStmt); - n->extname = $3; - n->if_not_exists = false; - n->options = $5; - $$ = (Node *) n; - } - | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list - { - CreateExtensionStmt *n = makeNode(CreateExtensionStmt); - n->extname = $6; - n->if_not_exists = true; - n->options = $8; - $$ = (Node *) n; - } - ; - -create_extension_opt_list: - create_extension_opt_list create_extension_opt_item - { $$ = lappend($1, $2); } - | /* EMPTY */ - { $$ = NIL; } - ; - -create_extension_opt_item: - SCHEMA name - { - $$ = makeDefElem("schema", (Node *)makeString($2)); - } - | VERSION_P ColId_or_Sconst - { - $$ = makeDefElem("new_version", (Node *)makeString($2)); - } - | FROM ColId_or_Sconst - { - $$ = makeDefElem("old_version", (Node *)makeString($2)); - } - ; - -/***************************************************************************** - * - * ALTER EXTENSION name UPDATE [ TO version ] - * - *****************************************************************************/ - -AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list - { - AlterExtensionStmt *n = makeNode(AlterExtensionStmt); - n->extname = $3; - n->options = $5; - $$ = (Node *) n; - } - ; - -alter_extension_opt_list: - alter_extension_opt_list alter_extension_opt_item - { $$ = lappend($1, $2); } - | /* EMPTY */ - { $$ = NIL; } - ; - -alter_extension_opt_item: - TO ColId_or_Sconst - { - $$ = makeDefElem("new_version", (Node *)makeString($2)); - } - ; - -/***************************************************************************** - * - * ALTER EXTENSION name ADD/DROP object-identifier - * - *****************************************************************************/ - -AlterExtensionContentsStmt: - ALTER EXTENSION name add_drop AGGREGATE func_name aggr_args - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_AGGREGATE; - n->objname = $6; - n->objargs = $7; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')' - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_CAST; - n->objname = list_make1($7); - n->objargs = list_make1($9); - $$ = (Node *) n; - } - | ALTER EXTENSION name add_drop COLLATION any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_COLLATION; - n->objname = $6; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop CONVERSION_P any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_CONVERSION; - n->objname = $6; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop DOMAIN_P any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_DOMAIN; - n->objname = $6; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_FUNCTION; - n->objname = $6->funcname; - n->objargs = $6->funcargs; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop opt_procedural LANGUAGE name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_LANGUAGE; - n->objname = list_make1(makeString($7)); - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop OPERATOR any_operator oper_argtypes - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_OPERATOR; - n->objname = $6; - n->objargs = $7; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING access_method - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_OPCLASS; - n->objname = $7; - n->objargs = list_make1(makeString($9)); - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING access_method - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_OPFAMILY; - n->objname = $7; - n->objargs = list_make1(makeString($9)); - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop SCHEMA name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_SCHEMA; - n->objname = list_make1(makeString($6)); - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop TABLE any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_TABLE; - n->objname = $6; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop TEXT_P SEARCH PARSER any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_TSPARSER; - n->objname = $8; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop TEXT_P SEARCH DICTIONARY any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_TSDICTIONARY; - n->objname = $8; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop TEXT_P SEARCH TEMPLATE any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_TSTEMPLATE; - n->objname = $8; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop TEXT_P SEARCH CONFIGURATION any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_TSCONFIGURATION; - n->objname = $8; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop SEQUENCE any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_SEQUENCE; - n->objname = $6; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop VIEW any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_VIEW; - n->objname = $6; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop FOREIGN TABLE any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_FOREIGN_TABLE; - n->objname = $7; - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop FOREIGN DATA_P WRAPPER name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_FDW; - n->objname = list_make1(makeString($8)); - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop SERVER name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_FOREIGN_SERVER; - n->objname = list_make1(makeString($6)); - $$ = (Node *)n; - } - | ALTER EXTENSION name add_drop TYPE_P any_name - { - AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt); - n->extname = $3; - n->action = $4; - n->objtype = OBJECT_TYPE; - n->objname = $6; - $$ = (Node *)n; - } - ; - -/***************************************************************************** - * - * QUERY: - * CREATE FOREIGN DATA WRAPPER name options - * - *****************************************************************************/ - -CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options - { - CreateFdwStmt *n = makeNode(CreateFdwStmt); - n->fdwname = $5; - n->func_options = $6; - n->options = $7; - $$ = (Node *) n; - } - ; - -fdw_option: - HANDLER handler_name { $$ = makeDefElem("handler", (Node *)$2); } - | NO HANDLER { $$ = makeDefElem("handler", NULL); } - | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *)$2); } - | NO VALIDATOR { $$ = makeDefElem("validator", NULL); } - ; - -fdw_options: - fdw_option { $$ = list_make1($1); } - | fdw_options fdw_option { $$ = lappend($1, $2); } - ; - -opt_fdw_options: - fdw_options { $$ = $1; } - | /*EMPTY*/ { $$ = NIL; } - ; - -/***************************************************************************** - * - * QUERY : - * DROP FOREIGN DATA WRAPPER name - * - ****************************************************************************/ - -DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior - { - DropFdwStmt *n = makeNode(DropFdwStmt); - n->fdwname = $5; - n->missing_ok = false; - n->behavior = $6; - $$ = (Node *) n; - } - | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior - { - DropFdwStmt *n = makeNode(DropFdwStmt); - n->fdwname = $7; - n->missing_ok = true; - n->behavior = $8; - $$ = (Node *) n; - } - ; - -/***************************************************************************** - * - * QUERY : - * ALTER FOREIGN DATA WRAPPER name options - * - ****************************************************************************/ - -AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options - { - AlterFdwStmt *n = makeNode(AlterFdwStmt); - n->fdwname = $5; - n->func_options = $6; - n->options = $7; - $$ = (Node *) n; - } - | ALTER FOREIGN DATA_P WRAPPER name fdw_options - { - AlterFdwStmt *n = makeNode(AlterFdwStmt); - n->fdwname = $5; - n->func_options = $6; - n->options = NIL; - $$ = (Node *) n; - } - ; - -/* Options definition for CREATE FDW, SERVER and USER MAPPING */ -create_generic_options: - OPTIONS '(' generic_option_list ')' { $$ = $3; } - | /*EMPTY*/ { $$ = NIL; } - ; - -generic_option_list: - generic_option_elem - { - $$ = list_make1($1); - } - | generic_option_list ',' generic_option_elem - { - $$ = lappend($1, $3); - } - ; - -/* Options definition for ALTER FDW, SERVER and USER MAPPING */ -alter_generic_options: - OPTIONS '(' alter_generic_option_list ')' { $$ = $3; } - ; - -alter_generic_option_list: - alter_generic_option_elem - { - $$ = list_make1($1); - } - | alter_generic_option_list ',' alter_generic_option_elem - { - $$ = lappend($1, $3); - } - ; - -alter_generic_option_elem: - generic_option_elem - { - $$ = $1; - } - | SET generic_option_elem - { - $$ = $2; - $$->defaction = DEFELEM_SET; - } - | ADD_P generic_option_elem - { - $$ = $2; - $$->defaction = DEFELEM_ADD; - } - | DROP generic_option_name - { - $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP); - } - ; - -generic_option_elem: - generic_option_name generic_option_arg - { - $$ = makeDefElem($1, $2); - } - ; - -generic_option_name: - ColLabel { $$ = $1; } - ; - -/* We could use def_arg here, but the spec only requires string literals */ -generic_option_arg: - Sconst { $$ = (Node *) makeString($1); } - ; - -/***************************************************************************** - * - * QUERY: - * CREATE SERVER name [TYPE] [VERSION] [OPTIONS] - * - *****************************************************************************/ - -CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version - FOREIGN DATA_P WRAPPER name create_generic_options - { - CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt); - n->servername = $3; - n->servertype = $4; - n->version = $5; - n->fdwname = $9; - n->options = $10; - $$ = (Node *) n; - } - ; - -opt_type: - TYPE_P Sconst { $$ = $2; } - | /*EMPTY*/ { $$ = NULL; } - ; - - -foreign_server_version: - VERSION_P Sconst { $$ = $2; } - | VERSION_P NULL_P { $$ = NULL; } - ; - -opt_foreign_server_version: - foreign_server_version { $$ = $1; } - | /*EMPTY*/ { $$ = NULL; } - ; - -/***************************************************************************** - * - * QUERY : - * DROP SERVER name - * - ****************************************************************************/ - -DropForeignServerStmt: DROP SERVER name opt_drop_behavior - { - DropForeignServerStmt *n = makeNode(DropForeignServerStmt); - n->servername = $3; - n->missing_ok = false; - n->behavior = $4; - $$ = (Node *) n; - } - | DROP SERVER IF_P EXISTS name opt_drop_behavior - { - DropForeignServerStmt *n = makeNode(DropForeignServerStmt); - n->servername = $5; - n->missing_ok = true; - n->behavior = $6; - $$ = (Node *) n; - } - ; - -/***************************************************************************** - * - * QUERY : - * ALTER SERVER name [VERSION] [OPTIONS] - * - ****************************************************************************/ - -AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options - { - AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt); - n->servername = $3; - n->version = $4; - n->options = $5; - n->has_version = true; - $$ = (Node *) n; - } - | ALTER SERVER name foreign_server_version - { - AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt); - n->servername = $3; - n->version = $4; - n->has_version = true; - $$ = (Node *) n; - } - | ALTER SERVER name alter_generic_options - { - AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt); - n->servername = $3; - n->options = $4; - $$ = (Node *) n; - } - ; - -/***************************************************************************** - * - * QUERY: - * CREATE FOREIGN TABLE relname (...) SERVER name (...) - * - *****************************************************************************/ - -CreateForeignTableStmt: - CREATE FOREIGN TABLE qualified_name - OptForeignTableElementList - SERVER name create_generic_options - { - CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt); - $4->relpersistence = RELPERSISTENCE_PERMANENT; - n->base.relation = $4; - n->base.tableElts = $5; - n->base.inhRelations = NIL; - n->base.if_not_exists = false; - /* FDW-specific data */ - n->servername = $7; - n->options = $8; - $$ = (Node *) n; - } - | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name - OptForeignTableElementList - SERVER name create_generic_options - { - CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt); - $7->relpersistence = RELPERSISTENCE_PERMANENT; - n->base.relation = $7; - n->base.tableElts = $8; - n->base.inhRelations = NIL; - n->base.if_not_exists = true; - /* FDW-specific data */ - n->servername = $10; - n->options = $11; - $$ = (Node *) n; - } - ; - -OptForeignTableElementList: - '(' ForeignTableElementList ')' { $$ = $2; } - | '(' ')' { $$ = NIL; } - ; - -ForeignTableElementList: - ForeignTableElement - { - $$ = list_make1($1); - } - | ForeignTableElementList ',' ForeignTableElement - { - $$ = lappend($1, $3); - } - ; - -ForeignTableElement: - columnDef { $$ = $1; } - ; - -/***************************************************************************** - * - * QUERY: - * ALTER FOREIGN TABLE relname [...] - * - *****************************************************************************/ - -AlterForeignTableStmt: - ALTER FOREIGN TABLE relation_expr alter_table_cmds - { - AlterTableStmt *n = makeNode(AlterTableStmt); - n->relation = $4; - n->cmds = $5; - n->relkind = OBJECT_FOREIGN_TABLE; - $$ = (Node *)n; - } - ; - -/***************************************************************************** - * - * QUERY: - * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS] - * - *****************************************************************************/ - -CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options - { - CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt); - n->username = $5; - n->servername = $7; - n->options = $8; - $$ = (Node *) n; - } - ; - -/* User mapping authorization identifier */ -auth_ident: - CURRENT_USER { $$ = "current_user"; } - | USER { $$ = "current_user"; } - | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; } - ; - -/***************************************************************************** - * - * QUERY : - * DROP USER MAPPING FOR auth_ident SERVER name - * - ****************************************************************************/ - -DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name - { - DropUserMappingStmt *n = makeNode(DropUserMappingStmt); - n->username = $5; - n->servername = $7; - n->missing_ok = false; - $$ = (Node *) n; - } - | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name - { - DropUserMappingStmt *n = makeNode(DropUserMappingStmt); - n->username = $7; - n->servername = $9; - n->missing_ok = true; - $$ = (Node *) n; - } - ; - -/***************************************************************************** - * - * QUERY : - * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS - * - ****************************************************************************/ - -AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options - { - AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt); - n->username = $5; - n->servername = $7; - n->options = $8; - $$ = (Node *) n; - } - ; - -/***************************************************************************** - * - * QUERIES : - * CREATE TRIGGER ... - * DROP TRIGGER ... - * - *****************************************************************************/ - -CreateTrigStmt: - CREATE TRIGGER name TriggerActionTime TriggerEvents ON - qualified_name TriggerForSpec TriggerWhen - EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')' - { - CreateTrigStmt *n = makeNode(CreateTrigStmt); - n->trigname = $3; - n->relation = $7; - n->funcname = $12; - n->args = $14; - n->row = $8; - n->timing = $4; - n->events = intVal(linitial($5)); - n->columns = (List *) lsecond($5); - n->whenClause = $9; - n->isconstraint = FALSE; - n->deferrable = FALSE; - n->initdeferred = FALSE; - n->constrrel = NULL; - $$ = (Node *)n; - } - | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON - qualified_name OptConstrFromTable ConstraintAttributeSpec - FOR EACH ROW TriggerWhen - EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')' - { - CreateTrigStmt *n = makeNode(CreateTrigStmt); - n->trigname = $4; - n->relation = $8; - n->funcname = $17; - n->args = $19; - n->row = TRUE; - n->timing = TRIGGER_TYPE_AFTER; - n->events = intVal(linitial($6)); - n->columns = (List *) lsecond($6); - n->whenClause = $14; - n->isconstraint = TRUE; - n->deferrable = ($10 & 1) != 0; - n->initdeferred = ($10 & 2) != 0; - n->constrrel = $9; - $$ = (Node *)n; - } - ; - -TriggerActionTime: - BEFORE { $$ = TRIGGER_TYPE_BEFORE; } - | AFTER { $$ = TRIGGER_TYPE_AFTER; } - | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; } - ; - -TriggerEvents: - TriggerOneEvent - { $$ = $1; } - | TriggerEvents OR TriggerOneEvent - { - int events1 = intVal(linitial($1)); - int events2 = intVal(linitial($3)); - List *columns1 = (List *) lsecond($1); - List *columns2 = (List *) lsecond($3); - - if (events1 & events2) - parser_yyerror("duplicate trigger events specified"); - /* - * concat'ing the columns lists loses information about - * which columns went with which event, but so long as - * only UPDATE carries columns and we disallow multiple - * UPDATE items, it doesn't matter. Command execution - * should just ignore the columns for non-UPDATE events. - */ - $$ = list_make2(makeInteger(events1 | events2), - list_concat(columns1, columns2)); - } - ; - -TriggerOneEvent: - INSERT - { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); } - | DELETE_P - { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); } - | UPDATE - { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); } - | UPDATE OF columnList - { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); } - | TRUNCATE - { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); } - ; - -TriggerForSpec: - FOR TriggerForOptEach TriggerForType - { - $$ = $3; - } - | /* EMPTY */ - { - /* - * If ROW/STATEMENT not specified, default to - * STATEMENT, per SQL - */ - $$ = FALSE; - } - ; - -TriggerForOptEach: - EACH {} - | /*EMPTY*/ {} - ; - -TriggerForType: - ROW { $$ = TRUE; } - | STATEMENT { $$ = FALSE; } - ; - -TriggerWhen: - WHEN '(' a_expr ')' { $$ = $3; } - | /*EMPTY*/ { $$ = NULL; } - ; - -TriggerFuncArgs: - TriggerFuncArg { $$ = list_make1($1); } - | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); } - | /*EMPTY*/ { $$ = NIL; } - ; - -TriggerFuncArg: - Iconst - { - char buf[64]; - snprintf(buf, sizeof(buf), "%d", $1); - $$ = makeString(pstrdup(buf)); - } - | FCONST { $$ = makeString($1); } - | Sconst { $$ = makeString($1); } - | ColLabel { $$ = makeString($1); } - ; - -OptConstrFromTable: - FROM qualified_name { $$ = $2; } - | /*EMPTY*/ { $$ = NULL; } - ; - -ConstraintAttributeSpec: - ConstraintDeferrabilitySpec - { $$ = $1; } - | ConstraintDeferrabilitySpec ConstraintTimeSpec - { - if ($1 == 0 && $2 != 0) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"), - parser_errposition(@1))); - $$ = $1 | $2; - } - | ConstraintTimeSpec - { - if ($1 != 0) - $$ = 3; - else - $$ = 0; - } - | ConstraintTimeSpec ConstraintDeferrabilitySpec - { - if ($2 == 0 && $1 != 0) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"), - parser_errposition(@1))); - $$ = $1 | $2; - } - | /*EMPTY*/ - { $$ = 0; } - ; - -ConstraintDeferrabilitySpec: - NOT DEFERRABLE { $$ = 0; } - | DEFERRABLE { $$ = 1; } - ; - -ConstraintTimeSpec: - INITIALLY IMMEDIATE { $$ = 0; } - | INITIALLY DEFERRED { $$ = 2; } - ; - - -DropTrigStmt: - DROP TRIGGER name ON qualified_name opt_drop_behavior - { - DropPropertyStmt *n = makeNode(DropPropertyStmt); - n->relation = $5; - n->property = $3; - n->behavior = $6; - n->removeType = OBJECT_TRIGGER; - n->missing_ok = false; - $$ = (Node *) n; - } - | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior - { - DropPropertyStmt *n = makeNode(DropPropertyStmt); - n->relation = $7; - n->property = $5; - n->behavior = $8; - n->removeType = OBJECT_TRIGGER; - n->missing_ok = true; - $$ = (Node *) n; - } - ; - - -/***************************************************************************** - * - * QUERIES : - * CREATE ASSERTION ... - * DROP ASSERTION ... - * - *****************************************************************************/ - -CreateAssertStmt: - CREATE ASSERTION name CHECK '(' a_expr ')' - ConstraintAttributeSpec - { - CreateTrigStmt *n = makeNode(CreateTrigStmt); - n->trigname = $3; - n->args = list_make1($6); - n->isconstraint = TRUE; - n->deferrable = ($8 & 1) != 0; - n->initdeferred = ($8 & 2) != 0; - - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("CREATE ASSERTION is not yet implemented"))); - - $$ = (Node *)n; - } - ; - -DropAssertStmt: - DROP ASSERTION name opt_drop_behavior - { - DropPropertyStmt *n = makeNode(DropPropertyStmt); - n->relation = NULL; - n->property = $3; - n->behavior = $4; - n->removeType = OBJECT_TRIGGER; /* XXX */ - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("DROP ASSERTION is not yet implemented"))); - $$ = (Node *) n; - } - ; - - -/***************************************************************************** - * - * QUERY : - * define (aggregate,operator,type) - * - *****************************************************************************/ - -DefineStmt: - CREATE AGGREGATE func_name aggr_args definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_AGGREGATE; - n->oldstyle = false; - n->defnames = $3; - n->args = $4; - n->definition = $5; - $$ = (Node *)n; - } - | CREATE AGGREGATE func_name old_aggr_definition - { - /* old-style (pre-8.2) syntax for CREATE AGGREGATE */ - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_AGGREGATE; - n->oldstyle = true; - n->defnames = $3; - n->args = NIL; - n->definition = $4; - $$ = (Node *)n; - } - | CREATE OPERATOR any_operator definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_OPERATOR; - n->oldstyle = false; - n->defnames = $3; - n->args = NIL; - n->definition = $4; - $$ = (Node *)n; - } - | CREATE TYPE_P any_name definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_TYPE; - n->oldstyle = false; - n->defnames = $3; - n->args = NIL; - n->definition = $4; - $$ = (Node *)n; - } - | CREATE TYPE_P any_name - { - /* Shell type (identified by lack of definition) */ - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_TYPE; - n->oldstyle = false; - n->defnames = $3; - n->args = NIL; - n->definition = NIL; - $$ = (Node *)n; - } - | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')' - { - CompositeTypeStmt *n = makeNode(CompositeTypeStmt); - - /* can't use qualified_name, sigh */ - n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner); - n->coldeflist = $6; - $$ = (Node *)n; - } - | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')' - { - CreateEnumStmt *n = makeNode(CreateEnumStmt); - n->typeName = $3; - n->vals = $7; - $$ = (Node *)n; - } - | CREATE TEXT_P SEARCH PARSER any_name definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_TSPARSER; - n->args = NIL; - n->defnames = $5; - n->definition = $6; - $$ = (Node *)n; - } - | CREATE TEXT_P SEARCH DICTIONARY any_name definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_TSDICTIONARY; - n->args = NIL; - n->defnames = $5; - n->definition = $6; - $$ = (Node *)n; - } - | CREATE TEXT_P SEARCH TEMPLATE any_name definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_TSTEMPLATE; - n->args = NIL; - n->defnames = $5; - n->definition = $6; - $$ = (Node *)n; - } - | CREATE TEXT_P SEARCH CONFIGURATION any_name definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_TSCONFIGURATION; - n->args = NIL; - n->defnames = $5; - n->definition = $6; - $$ = (Node *)n; - } - | CREATE COLLATION any_name definition - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_COLLATION; - n->args = NIL; - n->defnames = $3; - n->definition = $4; - $$ = (Node *)n; - } - | CREATE COLLATION any_name FROM any_name - { - DefineStmt *n = makeNode(DefineStmt); - n->kind = OBJECT_COLLATION; - n->args = NIL; - n->defnames = $3; - n->definition = list_make1(makeDefElem("from", (Node *) $5)); - $$ = (Node *)n; - } - ; - -definition: '(' def_list ')' { $$ = $2; } - ; - -def_list: def_elem { $$ = list_make1($1); } - | def_list ',' def_elem { $$ = lappend($1, $3); } - ; - -def_elem: ColLabel '=' def_arg - { - $$ = makeDefElem($1, (Node *) $3); - } - | ColLabel - { - $$ = makeDefElem($1, NULL); - } - ; - -/* Note: any simple identifier will be returned as a type name! */ -def_arg: func_type { $$ = (Node *)$1; } - | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); } - | qual_all_Op { $$ = (Node *)$1; } - | NumericOnly { $$ = (Node *)$1; } - | Sconst { $$ = (Node *)makeString($1); } - ; - -aggr_args: '(' type_list ')' { $$ = $2; } - | '(' '*' ')' { $$ = NIL; } - ; - -old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; } - ; - -old_aggr_list: old_aggr_elem { $$ = list_make1($1); } - | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); } - ; - -/* - * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of - * the item names needed in old aggregate definitions are likely to become - * SQL keywords. - */ -old_aggr_elem: IDENT '=' def_arg - { - $$ = makeDefElem($1, (Node *)$3); - } - ; - -opt_enum_val_list: - enum_val_list { $$ = $1; } - | /*EMPTY*/ { $$ = NIL; } - ; - -enum_val_list: Sconst - { $$ = list_make1(makeString($1)); } - | enum_val_list ',' Sconst - { $$ = lappend($1, makeString($3)); } - ; - -/***************************************************************************** - * - * ALTER TYPE enumtype ADD ... - * - *****************************************************************************/ - -AlterEnumStmt: - ALTER TYPE_P any_name ADD_P VALUE_P Sconst - { - AlterEnumStmt *n = makeNode(AlterEnumStmt); - n->typeName = $3; - n->newVal = $6; - n->newValNeighbor = NULL; - n->newValIsAfter = true; - $$ = (Node *) n; - } - | ALTER TYPE_P any_name ADD_P VALUE_P Sconst BEFORE Sconst - { - AlterEnumStmt *n = makeNode(AlterEnumStmt); - n->typeName = $3; - n->newVal = $6; - n->newValNeighbor = $8; - n->newValIsAfter = false; - $$ = (Node *) n; - } - | ALTER TYPE_P any_name ADD_P VALUE_P Sconst AFTER Sconst - { - AlterEnumStmt *n = makeNode(AlterEnumStmt); - n->typeName = $3; - n->newVal = $6; - n->newValNeighbor = $8; - n->newValIsAfter = true; - $$ = (Node *) n; - } - ; - - -/***************************************************************************** - * - * QUERIES : - * CREATE OPERATOR CLASS ... - * CREATE OPERATOR FAMILY ... - * ALTER OPERATOR FAMILY ... - * DROP OPERATOR CLASS ... - * DROP OPERATOR FAMILY ... - * - *****************************************************************************/ - -CreateOpClassStmt: - CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename - USING access_method opt_opfamily AS opclass_item_list - { - CreateOpClassStmt *n = makeNode(CreateOpClassStmt); - n->opclassname = $4; - n->isDefault = $5; - n->datatype = $8; - n->amname = $10; - n->opfamilyname = $11; - n->items = $13; - $$ = (Node *) n; - } - ; - -opclass_item_list: - opclass_item { $$ = list_make1($1); } - | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); } - ; - -opclass_item: - OPERATOR Iconst any_operator opclass_purpose opt_recheck - { - CreateOpClassItem *n = makeNode(CreateOpClassItem); - n->itemtype = OPCLASS_ITEM_OPERATOR; - n->name = $3; - n->args = NIL; - n->number = $2; - n->order_family = $4; - $$ = (Node *) n; - } - | OPERATOR Iconst any_operator oper_argtypes opclass_purpose - opt_recheck - { - CreateOpClassItem *n = makeNode(CreateOpClassItem); - n->itemtype = OPCLASS_ITEM_OPERATOR; - n->name = $3; - n->args = $4; - n->number = $2; - n->order_family = $5; - $$ = (Node *) n; - } - | FUNCTION Iconst func_name func_args - { - CreateOpClassItem *n = makeNode(CreateOpClassItem); - n->itemtype = OPCLASS_ITEM_FUNCTION; - n->name = $3; - n->args = extractArgTypes($4); - n->number = $2; - $$ = (Node *) n; - } - | FUNCTION Iconst '(' type_list ')' func_name func_args - { - CreateOpClassItem *n = makeNode(CreateOpClassItem); - n->itemtype = OPCLASS_ITEM_FUNCTION; - n->name = $6; - n->args = extractArgTypes($7); - n->number = $2; - n->class_args = $4; - $$ = (Node *) n; - } - | STORAGE Typename - { - CreateOpClassItem *n = makeNode(CreateOpClassItem); - n->itemtype = OPCLASS_ITEM_STORAGETYPE; - n->storedtype = $2; - $$ = (Node *) n; - } - ; - -opt_default: DEFAULT { $$ = TRUE; } - | /*EMPTY*/ { $$ = FALSE; } - ; - -opt_opfamily: FAMILY any_name { $$ = $2; } - | /*EMPTY*/ { $$ = NIL; } - ; - -opclass_purpose: FOR SEARCH { $$ = NIL; } - | FOR ORDER BY any_name { $$ = $4; } - | /*EMPTY*/ { $$ = NIL; } - ; - -opt_recheck: RECHECK - { - /* - * RECHECK no longer does anything in opclass definitions, - * but we still accept it to ease porting of old database - * dumps. - */ - ereport(NOTICE, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("RECHECK is no longer required"), - errhint("Update your data type."), - parser_errposition(@1))); - $$ = TRUE; - } - | /*EMPTY*/ { $$ = FALSE; } - ; - - -CreateOpFamilyStmt: - CREATE OPERATOR FAMILY any_name USING access_method - { - CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt); - n->opfamilyname = $4; - n->amname = $6; - $$ = (Node *) n; - } - ; - -AlterOpFamilyStmt: - ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list - { - AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt); - n->opfamilyname = $4; - n->amname = $6; - n->isDrop = false; - n->items = $8; - $$ = (Node *) n; - } - | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list - { - AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt); - n->opfamilyname = $4; - n->amname = $6; - n->isDrop = true; - n->items = $8; - $$ = (Node *) n; - } - ; - -opclass_drop_list: - opclass_drop { $$ = list_make1($1); } - | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); } - ; - -opclass_drop: - OPERATOR Iconst '(' type_list ')' - { - CreateOpClassItem *n = makeNode(CreateOpClassItem); - n->itemtype = OPCLASS_ITEM_OPERATOR; - n->number = $2; - n->args = $4; - $$ = (Node *) n; - } - | FUNCTION Iconst '(' type_list ')' - { - CreateOpClassItem *n = makeNode(CreateOpClassItem); - n->itemtype = OPCLASS_ITEM_FUNCTION; - n->number = $2; - n->args = $4; - $$ = (Node *) n; - } - ; - - -DropOpClassStmt: - DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior - { - RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt); - n->opclassname = $4; - n->amname = $6; - n->behavior = $7; - n->missing_ok = false; - $$ = (Node *) n; - } - | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior - { - RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt); - n->opclassname = $6; - n->amname = $8; - n->behavior = $9; - n->missing_ok = true; - $$ = (Node *) n; - } - ; - -DropOpFamilyStmt: - DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior - { - RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt); - n->opfamilyname = $4; - n->amname = $6; - n->behavior = $7; - n->missing_ok = false; - $$ = (Node *) n; - } - | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior - { - RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt); - n->opfamilyname = $6; - n->amname = $8; - n->behavior = $9; - n->missing_ok = true; - $$ = (Node *) n; - } - ; - - -/***************************************************************************** - * - * QUERY: - * - * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ] - * REASSIGN OWNED BY username [, username ...] TO username - * - *****************************************************************************/ -DropOwnedStmt: - DROP OWNED BY name_list opt_drop_behavior - { - DropOwnedStmt *n = makeNode(DropOwnedStmt); - n->roles = $4; - n->behavior = $5; - $$ = (Node *)n; - } - ; - -ReassignOwnedStmt: - REASSIGN OWNED BY name_list TO name - { - ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt); - n->roles = $4; - n->newrole = $6; - $$ = (Node *)n; - } - ; - -/***************************************************************************** - * - * QUERY: - * - * DROP itemtype [ IF EXISTS ] itemname [, itemname ...] - * [ RESTRICT | CASCADE ] - * - *****************************************************************************/ - -DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior - { - DropStmt *n = makeNode(DropStmt); - n->removeType = $2; - n->missing_ok = TRUE; - n->objects = $5; - n->behavior = $6; - $$ = (Node *)n; - } - | DROP drop_type any_name_list opt_drop_behavior - { - DropStmt *n = makeNode(DropStmt); - n->removeType = $2; - n->missing_ok = FALSE; - n->objects = $3; - n->behavior = $4; - $$ = (Node *)n; - } - ; - - -drop_type: TABLE { $$ = OBJECT_TABLE; } - | SEQUENCE { $$ = OBJECT_SEQUENCE; } - | VIEW { $$ = OBJECT_VIEW; } - | INDEX { $$ = OBJECT_INDEX; } - | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; } - | TYPE_P { $$ = OBJECT_TYPE; } - | DOMAIN_P { $$ = OBJECT_DOMAIN; } - | COLLATION { $$ = OBJECT_COLLATION; } - | CONVERSION_P { $$ = OBJECT_CONVERSION; } - | SCHEMA { $$ = OBJECT_SCHEMA; } - | EXTENSION { $$ = OBJECT_EXTENSION; } - | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; } - | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; } - | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; } - | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; } - ; - -any_name_list: - any_name { $$ = list_make1($1); } - | any_name_list ',' any_name { $$ = lappend($1, $3); } - ; - any_name: ColId { $$ = list_make1(makeString($1)); } | ColId attrs { $$ = lcons(makeString($1), $2); } ; @@ -4772,1006 +525,6 @@ attrs: '.' attr_name { $$ = lappend($1, makeString($3)); } ; - -/***************************************************************************** - * - * QUERY: - * truncate table relname1, relname2, ... - * - *****************************************************************************/ - -TruncateStmt: - TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior - { - TruncateStmt *n = makeNode(TruncateStmt); - n->relations = $3; - n->restart_seqs = $4; - n->behavior = $5; - $$ = (Node *)n; - } - ; - -opt_restart_seqs: - CONTINUE_P IDENTITY_P { $$ = false; } - | RESTART IDENTITY_P { $$ = true; } - | /* EMPTY */ { $$ = false; } - ; - -/***************************************************************************** - * - * The COMMENT ON statement can take different forms based upon the type of - * the object associated with the comment. The form of the statement is: - * - * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW | - * COLLATION | CONVERSION | LANGUAGE | OPERATOR CLASS | - * LARGE OBJECT | CAST | COLUMN | SCHEMA | TABLESPACE | - * EXTENSION | ROLE | TEXT SEARCH PARSER | - * TEXT SEARCH DICTIONARY | TEXT SEARCH TEMPLATE | - * TEXT SEARCH CONFIGURATION | FOREIGN TABLE | - * FOREIGN DATA WRAPPER | SERVER ] | - * AGGREGATE (arg1, ...) | - * FUNCTION (arg1, arg2, ...) | - * OPERATOR (leftoperand_typ, rightoperand_typ) | - * TRIGGER ON | - * CONSTRAINT ON | - * RULE ON ] - * IS 'text' - * - *****************************************************************************/ - -CommentStmt: - COMMENT ON comment_type any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = $3; - n->objname = $4; - n->objargs = NIL; - n->comment = $6; - $$ = (Node *) n; - } - | COMMENT ON AGGREGATE func_name aggr_args IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_AGGREGATE; - n->objname = $4; - n->objargs = $5; - n->comment = $7; - $$ = (Node *) n; - } - | COMMENT ON FUNCTION func_name func_args IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_FUNCTION; - n->objname = $4; - n->objargs = extractArgTypes($5); - n->comment = $7; - $$ = (Node *) n; - } - | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_OPERATOR; - n->objname = $4; - n->objargs = $5; - n->comment = $7; - $$ = (Node *) n; - } - | COMMENT ON CONSTRAINT name ON any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_CONSTRAINT; - n->objname = lappend($6, makeString($4)); - n->objargs = NIL; - n->comment = $8; - $$ = (Node *) n; - } - | COMMENT ON RULE name ON any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_RULE; - n->objname = lappend($6, makeString($4)); - n->objargs = NIL; - n->comment = $8; - $$ = (Node *) n; - } - | COMMENT ON RULE name IS comment_text - { - /* Obsolete syntax supported for awhile for compatibility */ - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_RULE; - n->objname = list_make1(makeString($4)); - n->objargs = NIL; - n->comment = $6; - $$ = (Node *) n; - } - | COMMENT ON TRIGGER name ON any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_TRIGGER; - n->objname = lappend($6, makeString($4)); - n->objargs = NIL; - n->comment = $8; - $$ = (Node *) n; - } - | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_OPCLASS; - n->objname = $5; - n->objargs = list_make1(makeString($7)); - n->comment = $9; - $$ = (Node *) n; - } - | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_OPFAMILY; - n->objname = $5; - n->objargs = list_make1(makeString($7)); - n->comment = $9; - $$ = (Node *) n; - } - | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_LARGEOBJECT; - n->objname = list_make1($5); - n->objargs = NIL; - n->comment = $7; - $$ = (Node *) n; - } - | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_CAST; - n->objname = list_make1($5); - n->objargs = list_make1($7); - n->comment = $10; - $$ = (Node *) n; - } - | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_LANGUAGE; - n->objname = $5; - n->objargs = NIL; - n->comment = $7; - $$ = (Node *) n; - } - | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_TSPARSER; - n->objname = $6; - n->comment = $8; - $$ = (Node *) n; - } - | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_TSDICTIONARY; - n->objname = $6; - n->comment = $8; - $$ = (Node *) n; - } - | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_TSTEMPLATE; - n->objname = $6; - n->comment = $8; - $$ = (Node *) n; - } - | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text - { - CommentStmt *n = makeNode(CommentStmt); - n->objtype = OBJECT_TSCONFIGURATION; - n->objname = $6; - n->comment = $8; - $$ = (Node *) n; - } - ; - -comment_type: - COLUMN { $$ = OBJECT_COLUMN; } - | DATABASE { $$ = OBJECT_DATABASE; } - | SCHEMA { $$ = OBJECT_SCHEMA; } - | INDEX { $$ = OBJECT_INDEX; } - | SEQUENCE { $$ = OBJECT_SEQUENCE; } - | TABLE { $$ = OBJECT_TABLE; } - | DOMAIN_P { $$ = OBJECT_DOMAIN; } - | TYPE_P { $$ = OBJECT_TYPE; } - | VIEW { $$ = OBJECT_VIEW; } - | COLLATION { $$ = OBJECT_COLLATION; } - | CONVERSION_P { $$ = OBJECT_CONVERSION; } - | TABLESPACE { $$ = OBJECT_TABLESPACE; } - | EXTENSION { $$ = OBJECT_EXTENSION; } - | ROLE { $$ = OBJECT_ROLE; } - | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; } - | SERVER { $$ = OBJECT_FOREIGN_SERVER; } - | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; } - ; - -comment_text: - Sconst { $$ = $1; } - | NULL_P { $$ = NULL; } - ; - - -/***************************************************************************** - * - * SECURITY LABEL [FOR ] ON IS