-<!-- $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>
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>
</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>
</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>
<secondary>current</secondary>
</indexterm>
+ <indexterm>
+ <primary>current_catalog</primary>
+ </indexterm>
+
<indexterm>
<primary>current_database</primary>
</indexterm>
<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>
<!--
-$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
-->
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>
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
*
*
* 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
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
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);
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 ')'
| CALLED
| CASCADE
| CASCADED
+ | CATALOG_P
| CHAIN
| CHARACTERISTICS
| CHECKPOINT
| BETWEEN
| BINARY
| CROSS
+ | CURRENT_SCHEMA
| FREEZE
| FULL
| ILIKE
| COLUMN
| CONSTRAINT
| CREATE
+ | CURRENT_CATALOG
| CURRENT_DATE
| CURRENT_ROLE
| CURRENT_TIME
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
{"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},
{"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},
-/* $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 */
%{
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
{ $$ = 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
{ $$ = 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 ')'
| 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"); }