]> granicus.if.org Git - postgresql/blobdiff - src/backend/parser/gram.y
From: t-ishii@sra.co.jp
[postgresql] / src / backend / parser / gram.y
index df4acded9aea76711806e13df3914c693268ed57..0d3924590e5f3a7ab7be25bbd835c24484a8e4b7 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.14 1998/07/15 15:56:36 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.19 1998/07/26 04:30:31 scrappy Exp $
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
 #include "utils/elog.h"
 #include "access/xact.h"
 
+#ifdef MULTIBYTE
+#include "mb/pg_wchar.h"
+#endif
+
 static char saved_relname[NAMEDATALEN];  /* need this for complex attributes */
 static bool QueryIsRule = FALSE;
 static List *saved_In_Expr = NIL;
@@ -121,12 +125,12 @@ Oid       param_type(int t); /* used in parse_expr.c */
                ProcedureStmt,  RecipeStmt, RemoveAggrStmt, RemoveOperStmt,
                RemoveFuncStmt, RemoveStmt,
                RenameStmt, RevokeStmt, RuleStmt, TransactionStmt, ViewStmt, LoadStmt,
-               CreatedbStmt, DestroydbStmt, VacuumStmt, CursorStmt, SubSelect,
+               CreatedbStmt, DestroydbStmt, VacuumStmt, CursorStmt, SubSelect, SubUnion,
                UpdateStmt, InsertStmt, SelectStmt, NotifyStmt, DeleteStmt, ClusterStmt,
                ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,
                CreateUserStmt, AlterUserStmt, DropUserStmt
 
-%type <str>            opt_database, location
+%type <str>    opt_database1, opt_database2, location, encoding
 
 %type <pboolean> user_createdb_clause, user_createuser_clause
 %type <str>   user_passwd_clause
@@ -171,6 +175,7 @@ Oid param_type(int t); /* used in parse_expr.c */
                                join_using
 %type <boolean>        opt_union
 %type <boolean>        opt_table
+%type <boolean>        opt_trans
 
 %type <node>   position_expr
 %type <list>   extract_list, position_list
@@ -262,7 +267,7 @@ Oid param_type(int t); /* used in parse_expr.c */
                GRANT, GROUP, HAVING, HOUR_P,
                IN, INNER_P, INSERT, INTERVAL, INTO, IS,
                JOIN, KEY, LANGUAGE, LEADING, LEFT, LIKE, LOCAL,
-               MATCH, MINUTE_P, MONTH_P,
+               MATCH, MINUTE_P, MONTH_P, NAMES,
                NATIONAL, NATURAL, NCHAR, NO, NOT, NOTIFY, NULL_P, NUMERIC,
                ON, OPTION, OR, ORDER, OUTER_P,
                PARTIAL, POSITION, PRECISION, PRIMARY, PRIVILEGES, PROCEDURE, PUBLIC,
@@ -290,7 +295,7 @@ Oid param_type(int t); /* used in parse_expr.c */
                NEW, NONE, NOTHING, NOTNULL, OIDS, OPERATOR, PROCEDURAL,
                RECIPE, RENAME, RESET, RETURNS, ROW, RULE,
                SEQUENCE, SETOF, SHOW, START, STATEMENT, STDIN, STDOUT, TRUSTED, 
-               VACUUM, VERBOSE, VERSION
+               VACUUM, VERBOSE, VERSION, ENCODING
 
 /* Keywords (obsolete; retain through next version for parser - thomas 1997-12-04) */
 %token ARCHIVE
@@ -334,7 +339,6 @@ Oid param_type(int t); /* used in parse_expr.c */
 %left          '.'
 %left          '[' ']'
 %nonassoc      TYPECAST
-%nonassoc      REDUCE
 %left          UNION
 %%
 
@@ -535,6 +539,17 @@ VariableSetStmt:  SET ColId TO var_value
                                        n->value = $4;
                                        $$ = (Node *) n;
                                }
+               | SET NAMES encoding
+                               {
+#ifdef MB
+                                       VariableSetStmt *n = makeNode(VariableSetStmt);
+                                       n->name  = "client_encoding";
+                                       n->value = $3;
+                                       $$ = (Node *) n;
+#else
+                                       elog(ERROR, "SET NAMES is not supported");
+#endif
+                               }
                ;
 
 var_value:  Sconst                     { $$ = $1; }
@@ -1979,74 +1994,41 @@ ListenStmt:  LISTEN relation_name
  *
  *****************************************************************************/
 
-TransactionStmt:  ABORT_TRANS TRANSACTION
+TransactionStmt: ABORT_TRANS opt_trans
                                {
                                        TransactionStmt *n = makeNode(TransactionStmt);
                                        n->command = ABORT_TRANS;
                                        $$ = (Node *)n;
                                }
-               | BEGIN_TRANS TRANSACTION
-                               {
-                                       TransactionStmt *n = makeNode(TransactionStmt);
-                                       n->command = BEGIN_TRANS;
-                                       $$ = (Node *)n;
-                               }
-               | BEGIN_TRANS WORK
+               | BEGIN_TRANS opt_trans
                                {
                                        TransactionStmt *n = makeNode(TransactionStmt);
                                        n->command = BEGIN_TRANS;
                                        $$ = (Node *)n;
                                }
-               | COMMIT WORK
+               | COMMIT opt_trans
                                {
                                        TransactionStmt *n = makeNode(TransactionStmt);
                                        n->command = END_TRANS;
                                        $$ = (Node *)n;
                                }
-               | END_TRANS TRANSACTION
+               | END_TRANS opt_trans
                                {
                                        TransactionStmt *n = makeNode(TransactionStmt);
                                        n->command = END_TRANS;
                                        $$ = (Node *)n;
                                }
-               | ROLLBACK WORK
-                               {
-                                       TransactionStmt *n = makeNode(TransactionStmt);
-                                       n->command = ABORT_TRANS;
-                                       $$ = (Node *)n;
-                               }
-
-               | ABORT_TRANS
+               | ROLLBACK opt_trans
                                {
                                        TransactionStmt *n = makeNode(TransactionStmt);
                                        n->command = ABORT_TRANS;
                                        $$ = (Node *)n;
                                }
-               | BEGIN_TRANS
-                               {
-                                       TransactionStmt *n = makeNode(TransactionStmt);
-                                       n->command = BEGIN_TRANS;
-                                       $$ = (Node *)n;
-                               }
-               | COMMIT
-                               {
-                                       TransactionStmt *n = makeNode(TransactionStmt);
-                                       n->command = END_TRANS;
-                                       $$ = (Node *)n;
-                               }
+               ;
 
-               | END_TRANS
-                               {
-                                       TransactionStmt *n = makeNode(TransactionStmt);
-                                       n->command = END_TRANS;
-                                       $$ = (Node *)n;
-                               }
-               | ROLLBACK
-                               {
-                                       TransactionStmt *n = makeNode(TransactionStmt);
-                                       n->command = ABORT_TRANS;
-                                       $$ = (Node *)n;
-                               }
+opt_trans: WORK                                                                        { $$ = TRUE; }
+               | TRANSACTION                                                   { $$ = TRUE; }
+               | /*EMPTY*/                                                             { $$ = TRUE; }
                ;
 
 
@@ -2094,16 +2076,45 @@ LoadStmt:  LOAD file_name
  *
  *****************************************************************************/
 
-CreatedbStmt:  CREATE DATABASE database_name opt_database
+CreatedbStmt:  CREATE DATABASE database_name WITH opt_database1 opt_database2
                                {
                                        CreatedbStmt *n = makeNode(CreatedbStmt);
+                                       if ($5 == NULL && $6 == NULL) {
+                                               elog(ERROR, "CREATE DATABASE WITH requires at least an option");
+                                       }
                                        n->dbname = $3;
-                                       n->dbpath = $4;
+                                       n->dbpath = $5;
+#ifdef MULTIBYTE
+                                       if ($6 != NULL) {
+                                               n->encoding = pg_char_to_encoding($6);
+                                               if (n->encoding < 0) {
+                                                       elog(ERROR, "invalid encoding name %s", $6);
+                                               }
+                                       } else {
+                                               n->encoding = GetTemplateEncoding();
+                                       }
+#else
+                                       elog(ERROR, "WITH ENCODING is not supported");
+#endif
+                                       $$ = (Node *)n;
+                               }
+               | CREATE DATABASE database_name
+                               {
+                                       CreatedbStmt *n = makeNode(CreatedbStmt);
+                                       n->dbname = $3;
+                                       n->dbpath = NULL;
+#ifdef MULTIBYTE
+                                       n->encoding = GetTemplateEncoding();
+#endif
                                        $$ = (Node *)n;
                                }
                ;
 
-opt_database:  WITH LOCATION '=' location              { $$ = $4; }
+opt_database1:  LOCATION '=' location                  { $$ = $3; }
+               | /*EMPTY*/                                                             { $$ = NULL; }
+               ;
+
+opt_database2:  ENCODING '=' encoding                  { $$ = $3; }
                | /*EMPTY*/                                                             { $$ = NULL; }
                ;
 
@@ -2112,6 +2123,11 @@ location:  Sconst                                                                { $$ = $1; }
                | /*EMPTY*/                                                             { $$ = NULL; }
                ;
 
+encoding:  Sconst                                                              { $$ = $1; }
+               | DEFAULT                                                               { $$ = NULL; }
+               | /*EMPTY*/                                                             { $$ = NULL; }
+               ;
+
 /*****************************************************************************
  *
  *             QUERY:
@@ -2421,6 +2437,23 @@ SelectStmt:  SELECT opt_unique res_target_list2
                                }
                ;
 
+SubSelect:  SELECT opt_unique res_target_list2
+                        from_clause where_clause
+                        group_clause having_clause
+                        union_clause
+                               {
+                                       SelectStmt *n = makeNode(SelectStmt);
+                                       n->unique = $2;
+                                       n->targetList = $3;
+                                       n->fromClause = $4;
+                                       n->whereClause = $5;
+                                       n->groupClause = $6;
+                                       n->havingClause = $7;
+                                       n->unionClause = $8;
+                                       $$ = (Node *)n;
+                               }
+               ;
+
 union_clause:  UNION opt_union select_list
                                {
                                        SelectStmt *n = (SelectStmt *)lfirst($3);
@@ -2431,20 +2464,19 @@ union_clause:  UNION opt_union select_list
                                { $$ = NIL; }
                ;
 
-select_list:  select_list UNION opt_union SubSelect
+select_list:  select_list UNION opt_union SubUnion
                                {
                                        SelectStmt *n = (SelectStmt *)$4;
                                        n->unionall = $3;
                                        $$ = lappend($1, $4);
                                }
-               | SubSelect
+               | SubUnion
                                { $$ = lcons($1, NIL); }
                ;
 
-SubSelect:     SELECT opt_unique res_target_list2
+SubUnion:      SELECT opt_unique res_target_list2
                         from_clause where_clause
                         group_clause having_clause
-                        union_clause
                                {
                                        SelectStmt *n = makeNode(SelectStmt);
                                        n->unique = $2;
@@ -2454,7 +2486,6 @@ SubSelect:        SELECT opt_unique res_target_list2
                                        n->whereClause = $5;
                                        n->groupClause = $6;
                                        n->havingClause = $7;
-                                       n->unionClause = $8;
                                        $$ = (Node *)n;
                                }
                ;
@@ -2574,9 +2605,6 @@ groupby:  ColId
 
 having_clause:  HAVING a_expr
                                {
-#if FALSE
-                                       elog(ERROR,"HAVING clause not yet implemented");
-#endif
                                        $$ = $2;
                                }
                | /*EMPTY*/                                                             { $$ = NULL; }
@@ -4490,6 +4518,7 @@ ColId:  IDENT                                                     { $$ = $1; }
                | DELIMITERS                                    { $$ = "delimiters"; }
                | DOUBLE                                                { $$ = "double"; }
                | EACH                                                  { $$ = "each"; }
+               | ENCODING                                              { $$ = "encoding"; }
                | FUNCTION                                              { $$ = "function"; }
                | INCREMENT                                             { $$ = "increment"; }
                | INDEX                                                 { $$ = "index"; }