Commit 0fec77ae authored by Peter Eisentraut's avatar Peter Eisentraut

SQL:2008 syntax CURRENT_CATALOG, CURRENT_SCHEMA, SET CATALOG, SET SCHEMA.

parent b1eeeb20
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.450 2008/10/14 17:12:32 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.451 2008/10/27 09:37:46 petere Exp $ -->
<chapter id="functions"> <chapter id="functions">
<title>Functions and Operators</title> <title>Functions and Operators</title>
...@@ -3184,7 +3184,8 @@ cast(-44 as bit(12)) <lineannotation>111111010100</lineannotation> ...@@ -3184,7 +3184,8 @@ cast(-44 as bit(12)) <lineannotation>111111010100</lineannotation>
function fails and returns null. To indicate the part of the function fails and returns null. To indicate the part of the
pattern that should be returned on success, the pattern must contain pattern that should be returned on success, the pattern must contain
two occurrences of the escape character followed by a double quote two occurrences of the escape character followed by a double quote
(<literal>"</>). The text matching the portion of the pattern (<literal>"</>). <!-- " font-lock sanity -->
The text matching the portion of the pattern
between these markers is returned. between these markers is returned.
</para> </para>
...@@ -10932,6 +10933,12 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]); ...@@ -10932,6 +10933,12 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
</thead> </thead>
<tbody> <tbody>
<row>
<entry><literal><function>current_catalog</function></literal></entry>
<entry><type>name</type></entry>
<entry>name of current database (called <quote>catalog</quote> in the SQL standard)</entry>
</row>
<row> <row>
<entry><literal><function>current_database</function>()</literal></entry> <entry><literal><function>current_database</function>()</literal></entry>
<entry><type>name</type></entry> <entry><type>name</type></entry>
...@@ -10939,7 +10946,7 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]); ...@@ -10939,7 +10946,7 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
</row> </row>
<row> <row>
<entry><literal><function>current_schema</function>()</literal></entry> <entry><literal><function>current_schema</function>[()]</literal></entry>
<entry><type>name</type></entry> <entry><type>name</type></entry>
<entry>name of current schema</entry> <entry>name of current schema</entry>
</row> </row>
...@@ -11055,6 +11062,10 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]); ...@@ -11055,6 +11062,10 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
<secondary>current</secondary> <secondary>current</secondary>
</indexterm> </indexterm>
<indexterm>
<primary>current_catalog</primary>
</indexterm>
<indexterm> <indexterm>
<primary>current_database</primary> <primary>current_database</primary>
</indexterm> </indexterm>
...@@ -11083,9 +11094,12 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]); ...@@ -11083,9 +11094,12 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
<note> <note>
<para> <para>
<function>current_user</function>, <function>session_user</function>, and <function>current_catalog</function>, <function>current_schema</function>,
<function>user</function> have special syntactic status in <acronym>SQL</acronym>: <function>current_user</function>, <function>session_user</function>,
they must be called without trailing parentheses. and <function>user</function> have special syntactic status
in <acronym>SQL</acronym>: they must be called without trailing
parentheses (optional in PostgreSQL in the case
of <function>current_schema</function>).
</para> </para>
</note> </note>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.92 2008/03/10 12:39:22 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.93 2008/10/27 09:37:47 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -150,6 +150,17 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep ...@@ -150,6 +150,17 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
special syntax: special syntax:
<variablelist> <variablelist>
<varlistentry>
<term><literal>SCHEMA</literal></term>
<listitem>
<para>
<literal>SET SCHEMA '<replaceable>value</>'</> is an alias for
<literal>SET search_path TO <replaceable>value</></>. Only one
schema can be specified using this syntax.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><literal>NAMES</literal></term> <term><literal>NAMES</literal></term>
<listitem> <listitem>
......
...@@ -295,8 +295,8 @@ F731 INSERT column privileges NO ...@@ -295,8 +295,8 @@ F731 INSERT column privileges NO
F741 Referential MATCH types NO no partial match yet F741 Referential MATCH types NO no partial match yet
F751 View CHECK enhancements NO F751 View CHECK enhancements NO
F761 Session management YES F761 Session management YES
F762 CURRENT_CATALOG NO same as current_database() F762 CURRENT_CATALOG YES
F763 CURRENT_SCHEMA NO same as current_schema() F763 CURRENT_SCHEMA YES
F771 Connection management YES F771 Connection management YES
F781 Self-referencing operations YES F781 Self-referencing operations YES
F791 Insensitive cursors YES F791 Insensitive cursors YES
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.629 2008/10/27 08:47:14 petere Exp $ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.630 2008/10/27 09:37:47 petere Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -401,12 +401,13 @@ static TypeName *TableFuncTypeName(List *columns); ...@@ -401,12 +401,13 @@ static TypeName *TableFuncTypeName(List *columns);
BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
BOOLEAN_P BOTH BY BOOLEAN_P BOTH BY
CACHE CALLED CASCADE CASCADED CASE CAST CHAIN CHAR_P CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
CREATEROLE CREATEUSER CROSS CSV CTYPE CURRENT_P CURRENT_DATE CURRENT_ROLE CREATEROLE CREATEUSER CROSS CSV CTYPE 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 CYCLE
DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
...@@ -1133,6 +1134,22 @@ set_rest: /* Generic SET syntaxes: */ ...@@ -1133,6 +1134,22 @@ set_rest: /* Generic SET syntaxes: */
n->args = $5; n->args = $5;
$$ = n; $$ = n;
} }
| CATALOG_P Sconst
{
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("current database cannot be changed"),
scanner_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 | NAMES opt_encoding
{ {
VariableSetStmt *n = makeNode(VariableSetStmt); VariableSetStmt *n = makeNode(VariableSetStmt);
...@@ -8401,6 +8418,28 @@ func_expr: func_name '(' ')' ...@@ -8401,6 +8418,28 @@ func_expr: func_name '(' ')'
n->location = @1; n->location = @1;
$$ = (Node *)n; $$ = (Node *)n;
} }
| CURRENT_CATALOG
{
FuncCall *n = makeNode(FuncCall);
n->funcname = SystemFuncName("current_database");
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
n->func_variadic = FALSE;
n->location = @1;
$$ = (Node *)n;
}
| CURRENT_SCHEMA
{
FuncCall *n = makeNode(FuncCall);
n->funcname = SystemFuncName("current_schema");
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
n->func_variadic = FALSE;
n->location = @1;
$$ = (Node *)n;
}
| CAST '(' a_expr AS Typename ')' | CAST '(' a_expr AS Typename ')'
{ $$ = makeTypeCast($3, $5, @1); } { $$ = makeTypeCast($3, $5, @1); }
| EXTRACT '(' extract_list ')' | EXTRACT '(' extract_list ')'
...@@ -9336,6 +9375,7 @@ unreserved_keyword: ...@@ -9336,6 +9375,7 @@ unreserved_keyword:
| CALLED | CALLED
| CASCADE | CASCADE
| CASCADED | CASCADED
| CATALOG_P
| CHAIN | CHAIN
| CHARACTERISTICS | CHARACTERISTICS
| CHECKPOINT | CHECKPOINT
...@@ -9625,6 +9665,7 @@ type_func_name_keyword: ...@@ -9625,6 +9665,7 @@ type_func_name_keyword:
| BETWEEN | BETWEEN
| BINARY | BINARY
| CROSS | CROSS
| CURRENT_SCHEMA
| FREEZE | FREEZE
| FULL | FULL
| ILIKE | ILIKE
...@@ -9667,6 +9708,7 @@ reserved_keyword: ...@@ -9667,6 +9708,7 @@ reserved_keyword:
| COLUMN | COLUMN
| CONSTRAINT | CONSTRAINT
| CREATE | CREATE
| CURRENT_CATALOG
| CURRENT_DATE | CURRENT_DATE
| CURRENT_ROLE | CURRENT_ROLE
| CURRENT_TIME | CURRENT_TIME
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.204 2008/10/22 11:00:34 petere Exp $ * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.205 2008/10/27 09:37:47 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -83,6 +83,7 @@ const ScanKeyword ScanKeywords[] = { ...@@ -83,6 +83,7 @@ const ScanKeyword ScanKeywords[] = {
{"cascaded", CASCADED, UNRESERVED_KEYWORD}, {"cascaded", CASCADED, UNRESERVED_KEYWORD},
{"case", CASE, RESERVED_KEYWORD}, {"case", CASE, RESERVED_KEYWORD},
{"cast", CAST, RESERVED_KEYWORD}, {"cast", CAST, RESERVED_KEYWORD},
{"catalog", CATALOG_P, UNRESERVED_KEYWORD},
{"chain", CHAIN, UNRESERVED_KEYWORD}, {"chain", CHAIN, UNRESERVED_KEYWORD},
{"char", CHAR_P, COL_NAME_KEYWORD}, {"char", CHAR_P, COL_NAME_KEYWORD},
{"character", CHARACTER, COL_NAME_KEYWORD}, {"character", CHARACTER, COL_NAME_KEYWORD},
...@@ -116,8 +117,10 @@ const ScanKeyword ScanKeywords[] = { ...@@ -116,8 +117,10 @@ const ScanKeyword ScanKeywords[] = {
{"csv", CSV, UNRESERVED_KEYWORD}, {"csv", CSV, UNRESERVED_KEYWORD},
{"ctype", CTYPE, UNRESERVED_KEYWORD}, {"ctype", CTYPE, UNRESERVED_KEYWORD},
{"current", CURRENT_P, UNRESERVED_KEYWORD}, {"current", CURRENT_P, UNRESERVED_KEYWORD},
{"current_catalog", CURRENT_CATALOG, RESERVED_KEYWORD},
{"current_date", CURRENT_DATE, RESERVED_KEYWORD}, {"current_date", CURRENT_DATE, RESERVED_KEYWORD},
{"current_role", CURRENT_ROLE, RESERVED_KEYWORD}, {"current_role", CURRENT_ROLE, RESERVED_KEYWORD},
{"current_schema", CURRENT_SCHEMA, TYPE_FUNC_NAME_KEYWORD},
{"current_time", CURRENT_TIME, RESERVED_KEYWORD}, {"current_time", CURRENT_TIME, RESERVED_KEYWORD},
{"current_timestamp", CURRENT_TIMESTAMP, RESERVED_KEYWORD}, {"current_timestamp", CURRENT_TIMESTAMP, RESERVED_KEYWORD},
{"current_user", CURRENT_USER, RESERVED_KEYWORD}, {"current_user", CURRENT_USER, RESERVED_KEYWORD},
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.377 2008/10/21 08:38:16 petere Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.378 2008/10/27 09:37:47 petere Exp $ */
/* Copyright comment */ /* Copyright comment */
%{ %{
...@@ -423,12 +423,13 @@ add_typedef(char *name, char * dimension, char * length, enum ECPGttype type_enu ...@@ -423,12 +423,13 @@ add_typedef(char *name, char * dimension, char * length, enum ECPGttype type_enu
BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
BOOLEAN_P BOTH BY BOOLEAN_P BOTH BY
CACHE CALLED CASCADE CASCADED CASE CAST CHAIN CHAR_P CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
CREATEROLE CREATEUSER CROSS CSV CTYPE CURRENT_P CURRENT_DATE CURRENT_ROLE CREATEROLE CREATEUSER CROSS CSV CTYPE 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 CYCLE
DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
...@@ -1217,6 +1218,10 @@ set_rest: /* Generic SET syntaxes: */ ...@@ -1217,6 +1218,10 @@ set_rest: /* Generic SET syntaxes: */
{ $$ = cat2_str(make_str("transaction"), $2); } { $$ = cat2_str(make_str("transaction"), $2); }
| SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
{ $$ = cat2_str(make_str("session characteristics as transaction"), $5); } { $$ = cat2_str(make_str("session characteristics as transaction"), $5); }
| CATALOG_P Sconst
{ $$ = cat2_str(make_str("catalog"), $2); }
| SCHEMA Sconst
{ $$ = cat2_str(make_str("schema"), $2); }
| NAMES opt_encoding | NAMES opt_encoding
{ $$ = cat2_str(make_str("names"), $2); } { $$ = cat2_str(make_str("names"), $2); }
| ROLE ColId_or_Sconst | ROLE ColId_or_Sconst
...@@ -4469,6 +4474,10 @@ func_expr: func_name '(' ')' ...@@ -4469,6 +4474,10 @@ func_expr: func_name '(' ')'
{ $$ = make_str("session_user"); } { $$ = make_str("session_user"); }
| USER | USER
{ $$ = make_str("user"); } { $$ = make_str("user"); }
| CURRENT_CATALOG
{ $$ = make_str("current_catalog"); }
| CURRENT_SCHEMA
{ $$ = make_str("current_schema"); }
| CAST '(' a_expr AS Typename ')' | CAST '(' a_expr AS Typename ')'
{ $$ = cat_str(5, make_str("cast("), $3, make_str("as"), $5, make_str(")")); } { $$ = cat_str(5, make_str("cast("), $3, make_str("as"), $5, make_str(")")); }
| EXTRACT '(' extract_list ')' | EXTRACT '(' extract_list ')'
...@@ -6867,10 +6876,12 @@ reserved_keyword: ...@@ -6867,10 +6876,12 @@ reserved_keyword:
| CONSTRAINT { $$ = make_str("constraint"); } | CONSTRAINT { $$ = make_str("constraint"); }
| CREATE { $$ = make_str("create"); } | CREATE { $$ = make_str("create"); }
| CURRENT_P { $$ = make_str("current"); } | CURRENT_P { $$ = make_str("current"); }
| CURRENT_CATALOG { $$ = make_str("current_catalog"); }
| CURRENT_DATE { $$ = make_str("current_date"); } | CURRENT_DATE { $$ = make_str("current_date"); }
| CURRENT_TIME { $$ = make_str("current_time"); } | CURRENT_TIME { $$ = make_str("current_time"); }
| CURRENT_TIMESTAMP { $$ = make_str("current_timestamp"); } | CURRENT_TIMESTAMP { $$ = make_str("current_timestamp"); }
| CURRENT_ROLE { $$ = make_str("current_role"); } | CURRENT_ROLE { $$ = make_str("current_role"); }
| CURRENT_SCHEMA { $$ = make_str("current_schema"); }
| CURRENT_USER { $$ = make_str("current_user"); } | CURRENT_USER { $$ = make_str("current_user"); }
| DEFAULT { $$ = make_str("default"); } | DEFAULT { $$ = make_str("default"); }
| DEFERRABLE { $$ = make_str("deferrable"); } | DEFERRABLE { $$ = make_str("deferrable"); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment