From ea4686e3e1f00910a19e18dd59f5c518345bb431 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 29 Jul 2002 22:14:11 +0000 Subject: Implement CREATE/DROP OPERATOR CLASS. Work still remains: need more documentation (xindex.sgml should be rewritten), need to teach pg_dump about it, need to update contrib modules that currently build pg_opclass entries by hand. Original patch by Bill Studenmund, grammar adjustments and general update for 7.3 by Tom Lane. --- src/backend/parser/gram.y | 111 +++++++++++++++++++++++++++++++++++++----- src/backend/parser/keywords.c | 4 +- 2 files changed, 102 insertions(+), 13 deletions(-) (limited to 'src/backend/parser') diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 0dcecc9d5a5..532cc1de0f6 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.349 2002/07/24 19:11:10 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.350 2002/07/29 22:14:10 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -136,11 +136,11 @@ static void doNegateFloat(Value *v); AlterTableStmt, AlterUserStmt, AlterUserSetStmt, AnalyzeStmt, ClosePortalStmt, ClusterStmt, CommentStmt, ConstraintsSetStmt, CopyStmt, CreateAsStmt, CreateCastStmt, - CreateDomainStmt, CreateGroupStmt, CreatePLangStmt, + CreateDomainStmt, CreateGroupStmt, CreateOpClassStmt, CreatePLangStmt, CreateSchemaStmt, CreateSeqStmt, CreateStmt, CreateAssertStmt, CreateTrigStmt, CreateUserStmt, CreatedbStmt, CursorStmt, DefineStmt, DeleteStmt, - DropGroupStmt, DropPLangStmt, DropStmt, + DropGroupStmt, DropOpClassStmt, DropPLangStmt, DropStmt, DropAssertStmt, DropTrigStmt, DropRuleStmt, DropCastStmt, DropUserStmt, DropdbStmt, ExplainStmt, FetchStmt, GrantStmt, IndexStmt, InsertStmt, ListenStmt, LoadStmt, @@ -156,7 +156,7 @@ static void doNegateFloat(Value *v); %type select_no_parens, select_with_parens, select_clause, simple_select -%type alter_column_default +%type alter_column_default, opclass_item %type add_drop %type opt_drop_behavior @@ -218,7 +218,7 @@ static void doNegateFloat(Value *v); target_list, update_target_list, insert_column_list, insert_target_list, def_list, opt_indirection, group_clause, TriggerFuncArgs, select_limit, - opt_select_limit + opt_select_limit, opclass_item_list %type into_clause, OptTempTableName @@ -240,7 +240,7 @@ static void doNegateFloat(Value *v); %type opt_instead, opt_cursor %type index_opt_unique, opt_verbose, opt_full -%type opt_freeze, opt_default +%type opt_freeze, opt_default, opt_recheck %type opt_binary, opt_oids, copy_delimiter %type copy_from @@ -326,7 +326,7 @@ static void doNegateFloat(Value *v); BOOLEAN, BY, CACHE, CALLED, CASCADE, CASE, CAST, CHAIN, CHAR_P, - CHARACTER, CHARACTERISTICS, CHECK, CHECKPOINT, CLOSE, + CHARACTER, CHARACTERISTICS, CHECK, CHECKPOINT, CLASS, CLOSE, CLUSTER, COALESCE, COLLATE, COLUMN, COMMENT, COMMIT, COMMITTED, CONSTRAINT, CONSTRAINTS, CONVERSION_P, COPY, CREATE, CREATEDB, CREATEUSER, CROSS, CURRENT_DATE, CURRENT_TIME, @@ -371,7 +371,7 @@ static void doNegateFloat(Value *v); PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE, PROCEDURAL, - READ, REAL, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE, + READ, REAL, RECHECK, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE, RESET, RESTRICT, RETURNS, REVOKE, RIGHT, ROLLBACK, ROW, RULE, @@ -481,6 +481,7 @@ stmt : | CreateSchemaStmt | CreateGroupStmt | CreateSeqStmt + | CreateOpClassStmt | CreatePLangStmt | CreateAssertStmt | CreateTrigStmt @@ -492,6 +493,7 @@ stmt : | CommentStmt | DropCastStmt | DropGroupStmt + | DropOpClassStmt | DropPLangStmt | DropAssertStmt | DropTrigStmt @@ -2265,6 +2267,93 @@ def_arg: func_return { $$ = (Node *)$1; } ; +/***************************************************************************** + * + * QUERIES : + * CREATE OPERATOR CLASS ... + * DROP OPERATOR CLASS ... + * + *****************************************************************************/ + +CreateOpClassStmt: + CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename + USING access_method AS opclass_item_list + { + CreateOpClassStmt *n = makeNode(CreateOpClassStmt); + n->opclassname = $4; + n->isDefault = $5; + n->datatype = $8; + n->amname = $10; + n->items = $12; + $$ = (Node *) n; + } + ; + +opclass_item_list: + opclass_item { $$ = makeList1($1); } + | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); } + ; + +opclass_item: + OPERATOR Iconst any_operator opt_recheck + { + CreateOpClassItem *n = makeNode(CreateOpClassItem); + n->itemtype = OPCLASS_ITEM_OPERATOR; + n->name = $3; + n->args = NIL; + n->number = $2; + n->recheck = $4; + $$ = (Node *) n; + } + | OPERATOR Iconst any_operator '(' oper_argtypes ')' opt_recheck + { + CreateOpClassItem *n = makeNode(CreateOpClassItem); + n->itemtype = OPCLASS_ITEM_OPERATOR; + n->name = $3; + n->args = $5; + n->number = $2; + n->recheck = $7; + $$ = (Node *) n; + } + | FUNCTION Iconst func_name func_args + { + CreateOpClassItem *n = makeNode(CreateOpClassItem); + n->itemtype = OPCLASS_ITEM_FUNCTION; + n->name = $3; + n->args = $4; + n->number = $2; + $$ = (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_recheck: RECHECK { $$ = TRUE; } + | /*EMPTY*/ { $$ = FALSE; } + ; + + +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; + $$ = (Node *) n; + } + ; + + /***************************************************************************** * * QUERY: @@ -3655,10 +3744,6 @@ CreateConversionStmt: } ; -opt_default: DEFAULT { $$ = TRUE; } - | /*EMPTY*/ { $$ = FALSE; } - ; - /***************************************************************************** * * QUERY: @@ -6624,6 +6709,7 @@ unreserved_keyword: | CHAIN | CHARACTERISTICS | CHECKPOINT + | CLASS | CLOSE | CLUSTER | COMMENT @@ -6715,6 +6801,7 @@ unreserved_keyword: | PROCEDURAL | PROCEDURE | READ + | RECHECK | REINDEX | RELATIVE | RENAME diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c index 02c9fcdda93..32733d8f546 100644 --- a/src/backend/parser/keywords.c +++ b/src/backend/parser/keywords.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.122 2002/07/18 23:11:28 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.123 2002/07/29 22:14:11 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -68,6 +68,7 @@ static const ScanKeyword ScanKeywords[] = { {"characteristics", CHARACTERISTICS}, {"check", CHECK}, {"checkpoint", CHECKPOINT}, + {"class", CLASS}, {"close", CLOSE}, {"cluster", CLUSTER}, {"coalesce", COALESCE}, @@ -232,6 +233,7 @@ static const ScanKeyword ScanKeywords[] = { {"procedure", PROCEDURE}, {"read", READ}, {"real", REAL}, + {"recheck", RECHECK}, {"references", REFERENCES}, {"reindex", REINDEX}, {"relative", RELATIVE}, -- cgit v1.2.3