Skip to content

Commit 669f1ea

Browse files
author
Commitfest Bot
committed
[CF 5985] v7 - CREATE SCHEMA ... CREATE DOMAIN support
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5985 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CACJufxGOtXuJD3VLOMUQr08Zt3=8HjH0KYk2NivYPuMbHG2JQg@mail.gmail.com Author(s): Jian He
2 parents 74b41f5 + a839fac commit 669f1ea

File tree

24 files changed

+619
-129
lines changed

24 files changed

+619
-129
lines changed

doc/src/sgml/ref/create_schema.sgml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ CREATE SCHEMA IF NOT EXISTS AUTHORIZATION <replaceable class="parameter">role_sp
100100
<listitem>
101101
<para>
102102
An SQL statement defining an object to be created within the
103-
schema. Currently, only <command>CREATE
104-
TABLE</command>, <command>CREATE VIEW</command>, <command>CREATE
103+
schema. Currently, only <command>CREATE COLLATION</command>,
104+
<command>CREATE DOMAIN</command>, <command>CREATE TABLE</command>,
105+
<command>CREATE VIEW</command>, <command>CREATE
105106
INDEX</command>, <command>CREATE SEQUENCE</command>, <command>CREATE
106-
TRIGGER</command> and <command>GRANT</command> are accepted as clauses
107+
TRIGGER</command>, <command>CREATE TYPE</command> and
108+
<command>GRANT</command> are accepted as clauses
107109
within <command>CREATE SCHEMA</command>. Other kinds of objects may
108110
be created in separate commands after the schema is created.
109111
</para>
@@ -193,12 +195,10 @@ CREATE VIEW hollywood.winners AS
193195
</para>
194196

195197
<para>
196-
The SQL standard specifies that the subcommands in <command>CREATE
197-
SCHEMA</command> can appear in any order. The present
198-
<productname>PostgreSQL</productname> implementation does not
199-
handle all cases of forward references in subcommands; it might
200-
sometimes be necessary to reorder the subcommands in order to avoid
201-
forward references.
198+
<productname>PostgreSQL</productname> executes the subcommands
199+
in <command>CREATE SCHEMA</command> in the order given. Other
200+
implementations may try to rearrange the subcommands into dependency
201+
order, but that is hard if not impossible to do correctly.
202202
</para>
203203

204204
<para>

src/backend/catalog/objectaddress.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,22 @@ read_objtype_from_string(const char *objtype)
26212621
return -1; /* keep compiler quiet */
26222622
}
26232623

2624+
const char *
2625+
stringify_objtype(ObjectType objtype)
2626+
{
2627+
int i;
2628+
2629+
for (i = 0; i < lengthof(ObjectTypeMap); i++)
2630+
{
2631+
if (ObjectTypeMap[i].tm_type == objtype)
2632+
return ObjectTypeMap[i].tm_name;
2633+
}
2634+
ereport(ERROR,
2635+
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2636+
errmsg("unrecognized object type %d", objtype));
2637+
2638+
return NULL; /* keep compiler quiet */
2639+
}
26242640
/*
26252641
* Interfaces to reference fields of ObjectPropertyType
26262642
*/

src/backend/commands/extension.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,14 +1773,17 @@ CreateExtensionInternal(char *extensionName,
17731773

17741774
if (!OidIsValid(schemaOid))
17751775
{
1776+
ParseState *pstate = make_parsestate(NULL);
17761777
CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt);
17771778

1779+
pstate->p_sourcetext = "(generated CREATE SCHEMA command)";
1780+
17781781
csstmt->schemaname = schemaName;
17791782
csstmt->authrole = NULL; /* will be created by current user */
17801783
csstmt->schemaElts = NIL;
17811784
csstmt->if_not_exists = false;
1782-
CreateSchemaCommand(csstmt, "(generated CREATE SCHEMA command)",
1783-
-1, -1);
1785+
1786+
CreateSchemaCommand(pstate, csstmt, -1, -1);
17841787

17851788
/*
17861789
* CreateSchemaCommand includes CommandCounterIncrement, so new

src/backend/commands/schemacmds.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerI
4949
* a subquery.
5050
*/
5151
Oid
52-
CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,
52+
CreateSchemaCommand(ParseState *pstate, CreateSchemaStmt *stmt,
5353
int stmt_location, int stmt_len)
5454
{
5555
const char *schemaName = stmt->schemaname;
@@ -189,12 +189,13 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,
189189

190190
/*
191191
* Examine the list of commands embedded in the CREATE SCHEMA command, and
192-
* reorganize them into a sequentially executable order with no forward
193-
* references. Note that the result is still a list of raw parsetrees ---
194-
* we cannot, in general, run parse analysis on one statement until we
195-
* have actually executed the prior ones.
192+
* do preliminary transformations (mostly, verify that none are trying to
193+
* create objects outside the new schema). Note that the result is still
194+
* a list of raw parsetrees --- we cannot, in general, run parse analysis
195+
* on one statement until we have actually executed the prior ones.
196196
*/
197-
parsetree_list = transformCreateSchemaStmtElements(stmt->schemaElts,
197+
parsetree_list = transformCreateSchemaStmtElements(pstate,
198+
stmt->schemaElts,
198199
schemaName);
199200

200201
/*
@@ -219,7 +220,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,
219220

220221
/* do this step */
221222
ProcessUtility(wrapper,
222-
queryString,
223+
pstate->p_sourcetext,
223224
false,
224225
PROCESS_UTILITY_SUBCOMMAND,
225226
NULL,

src/backend/parser/gram.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,8 @@ schema_stmt:
16271627
| CreateTrigStmt
16281628
| GrantStmt
16291629
| ViewStmt
1630+
| CreateDomainStmt
1631+
| DefineStmt
16301632
;
16311633

16321634

0 commit comments

Comments
 (0)