*
*
* 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;
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
join_using
%type <boolean> opt_union
%type <boolean> opt_table
+%type <boolean> opt_trans
%type <node> position_expr
%type <list> extract_list, position_list
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,
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
%left '.'
%left '[' ']'
%nonassoc TYPECAST
-%nonassoc REDUCE
%left UNION
%%
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; }
*
*****************************************************************************/
-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; }
;
*
*****************************************************************************/
-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; }
;
| /*EMPTY*/ { $$ = NULL; }
;
+encoding: Sconst { $$ = $1; }
+ | DEFAULT { $$ = NULL; }
+ | /*EMPTY*/ { $$ = NULL; }
+ ;
+
/*****************************************************************************
*
* QUERY:
}
;
+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);
{ $$ = 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;
n->whereClause = $5;
n->groupClause = $6;
n->havingClause = $7;
- n->unionClause = $8;
$$ = (Node *)n;
}
;
having_clause: HAVING a_expr
{
-#if FALSE
- elog(ERROR,"HAVING clause not yet implemented");
-#endif
$$ = $2;
}
| /*EMPTY*/ { $$ = NULL; }
| DELIMITERS { $$ = "delimiters"; }
| DOUBLE { $$ = "double"; }
| EACH { $$ = "each"; }
+ | ENCODING { $$ = "encoding"; }
| FUNCTION { $$ = "function"; }
| INCREMENT { $$ = "increment"; }
| INDEX { $$ = "index"; }