]> granicus.if.org Git - postgresql/commitdiff
SQL:2008 syntax CURRENT_CATALOG, CURRENT_SCHEMA, SET CATALOG, SET SCHEMA.
authorPeter Eisentraut <peter_e@gmx.net>
Mon, 27 Oct 2008 09:37:47 +0000 (09:37 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 27 Oct 2008 09:37:47 +0000 (09:37 +0000)
doc/src/sgml/func.sgml
doc/src/sgml/ref/set.sgml
src/backend/catalog/sql_features.txt
src/backend/parser/gram.y
src/backend/parser/keywords.c
src/interfaces/ecpg/preproc/preproc.y

index 06ee6a0572fd42e6fa4a0ca92136429e3462c41b..df6045fc70e7d186f644c3f41d45f0b91ed326fd 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $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">
   <title>Functions and Operators</title>
@@ -3184,7 +3184,8 @@ cast(-44 as bit(12))           <lineannotation>111111010100</lineannotation>
     function fails and returns null.  To indicate the part of the
     pattern that should be returned on success, the pattern must contain
     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.
    </para>
 
@@ -10932,6 +10933,12 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
      </thead>
 
      <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>
        <entry><literal><function>current_database</function>()</literal></entry>
        <entry><type>name</type></entry>
@@ -10939,7 +10946,7 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
       </row>
 
       <row>
-       <entry><literal><function>current_schema</function>()</literal></entry>
+       <entry><literal><function>current_schema</function>[()]</literal></entry>
        <entry><type>name</type></entry>
        <entry>name of current schema</entry>
       </row>
@@ -11055,6 +11062,10 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
     <secondary>current</secondary>
    </indexterm>
 
+   <indexterm>
+    <primary>current_catalog</primary>
+   </indexterm>
+
    <indexterm>
     <primary>current_database</primary>
    </indexterm>
@@ -11083,9 +11094,12 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
 
    <note>
     <para>
-     <function>current_user</function>, <function>session_user</function>, and
-     <function>user</function> have special syntactic status in <acronym>SQL</acronym>:
-     they must be called without trailing parentheses.
+     <function>current_catalog</function>, <function>current_schema</function>,
+     <function>current_user</function>, <function>session_user</function>,
+     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>
    </note>
 
index a31d15405261f5252b7cf3a2582d367589b85507..9174d52decb710c7ec5a3799e4991948be81c82c 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$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
 -->
 
@@ -150,6 +150,17 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
    special syntax:
 
    <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>
      <term><literal>NAMES</literal></term>
      <listitem>
index fdd393e7fef25a49ceb189847ca2bbadb3cef8c9..be9974af2718f63f0d9088fb77c891f1d074a170 100644 (file)
@@ -295,8 +295,8 @@ F731        INSERT column privileges                        NO
 F741   Referential MATCH types                 NO      no partial match yet
 F751   View CHECK enhancements                 NO      
 F761   Session management                      YES     
-F762   CURRENT_CATALOG                 NO      same as current_database()
-F763   CURRENT_SCHEMA                  NO      same as current_schema()
+F762   CURRENT_CATALOG                 YES     
+F763   CURRENT_SCHEMA                  YES     
 F771   Connection management                   YES     
 F781   Self-referencing operations                     YES     
 F791   Insensitive cursors                     YES     
index 172d45933e4f8ffe22e6c40a15bed74f7ece81c5..6a566fd400fc9a2395bd3950552870ea7256a2f1 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * 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
  *       AUTHOR                        DATE                    MAJOR EVENT
@@ -401,12 +401,13 @@ static TypeName *TableFuncTypeName(List *columns);
        BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
        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
        CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
        COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
        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
 
        DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
@@ -1133,6 +1134,22 @@ set_rest:        /* Generic SET syntaxes: */
                                        n->args = $5;
                                        $$ = 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
                                {
                                        VariableSetStmt *n = makeNode(VariableSetStmt);
@@ -8401,6 +8418,28 @@ func_expr:       func_name '(' ')'
                                        n->location = @1;
                                        $$ = (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 ')'
                                { $$ = makeTypeCast($3, $5, @1); }
                        | EXTRACT '(' extract_list ')'
@@ -9336,6 +9375,7 @@ unreserved_keyword:
                        | CALLED
                        | CASCADE
                        | CASCADED
+                       | CATALOG_P
                        | CHAIN
                        | CHARACTERISTICS
                        | CHECKPOINT
@@ -9625,6 +9665,7 @@ type_func_name_keyword:
                        | BETWEEN
                        | BINARY
                        | CROSS
+                       | CURRENT_SCHEMA
                        | FREEZE
                        | FULL
                        | ILIKE
@@ -9667,6 +9708,7 @@ reserved_keyword:
                        | COLUMN
                        | CONSTRAINT
                        | CREATE
+                       | CURRENT_CATALOG
                        | CURRENT_DATE
                        | CURRENT_ROLE
                        | CURRENT_TIME
index 608e80e0f5dc7ac7d46cfef959d8026070d4591c..9eb6d0822693bad5dba79c9e1139cb4cd74bd86a 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * 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[] = {
        {"cascaded", CASCADED, UNRESERVED_KEYWORD},
        {"case", CASE, RESERVED_KEYWORD},
        {"cast", CAST, RESERVED_KEYWORD},
+       {"catalog", CATALOG_P, UNRESERVED_KEYWORD},
        {"chain", CHAIN, UNRESERVED_KEYWORD},
        {"char", CHAR_P, COL_NAME_KEYWORD},
        {"character", CHARACTER, COL_NAME_KEYWORD},
@@ -116,8 +117,10 @@ const ScanKeyword ScanKeywords[] = {
        {"csv", CSV, UNRESERVED_KEYWORD},
        {"ctype", CTYPE, UNRESERVED_KEYWORD},
        {"current", CURRENT_P, UNRESERVED_KEYWORD},
+       {"current_catalog", CURRENT_CATALOG, RESERVED_KEYWORD},
        {"current_date", CURRENT_DATE, RESERVED_KEYWORD},
        {"current_role", CURRENT_ROLE, RESERVED_KEYWORD},
+       {"current_schema", CURRENT_SCHEMA, TYPE_FUNC_NAME_KEYWORD},
        {"current_time", CURRENT_TIME, RESERVED_KEYWORD},
        {"current_timestamp", CURRENT_TIMESTAMP, RESERVED_KEYWORD},
        {"current_user", CURRENT_USER, RESERVED_KEYWORD},
index 7220deff68a419d4ab9a88e0055c8a99cb29270f..038942da291bebda5f8b467be7bd92990c23f0ae 100644 (file)
@@ -1,4 +1,4 @@
-/* $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 */
 %{
@@ -423,12 +423,13 @@ add_typedef(char *name, char * dimension, char * length, enum ECPGttype type_enu
        BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
        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
        CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
        COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS 
        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
 
        DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
@@ -1217,6 +1218,10 @@ set_rest:        /* Generic SET syntaxes: */
                        { $$ = cat2_str(make_str("transaction"), $2); }
                | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
                        { $$ = 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
                        { $$ = cat2_str(make_str("names"), $2); }
                | ROLE ColId_or_Sconst
@@ -4469,6 +4474,10 @@ func_expr:      func_name '(' ')'
                        { $$ = make_str("session_user"); }
                | USER
                        { $$ = make_str("user"); }
+               | CURRENT_CATALOG
+                       { $$ = make_str("current_catalog"); }
+               | CURRENT_SCHEMA
+                       { $$ = make_str("current_schema"); }
                | CAST '(' a_expr AS Typename ')'
                        { $$ = cat_str(5, make_str("cast("), $3, make_str("as"), $5, make_str(")")); }
                | EXTRACT '(' extract_list ')'
@@ -6867,10 +6876,12 @@ reserved_keyword:
                | CONSTRAINT            { $$ = make_str("constraint"); }
                | CREATE                        { $$ = make_str("create"); }
                | CURRENT_P                     { $$ = make_str("current"); }
+               | CURRENT_CATALOG       { $$ = make_str("current_catalog"); }
                | CURRENT_DATE          { $$ = make_str("current_date"); }
                | CURRENT_TIME          { $$ = make_str("current_time"); }
                | CURRENT_TIMESTAMP     { $$ = make_str("current_timestamp"); }
                | CURRENT_ROLE          { $$ = make_str("current_role"); }
+               | CURRENT_SCHEMA        { $$ = make_str("current_schema"); }
                | CURRENT_USER          { $$ = make_str("current_user"); }
                | DEFAULT                       { $$ = make_str("default"); }
                | DEFERRABLE            { $$ = make_str("deferrable"); }