Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit db49517

Browse files
committed
Rename the internal structures of the CREATE TABLE (LIKE ...) facility
The original implementation of this interpreted it as a kind of "inheritance" facility and named all the internal structures accordingly. This turned out to be very confusing, because it has nothing to do with the INHERITS feature. So rename all the internal parser infrastructure, update the comments, adjust the error messages, and split up the regression tests.
1 parent 0a41e86 commit db49517

16 files changed

+431
-435
lines changed

doc/src/sgml/ref/create_table.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PostgreSQL documentation
2424
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable> ( [
2525
{ <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ COLLATE <replaceable>collation</replaceable> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
2626
| <replaceable>table_constraint</replaceable>
27-
| LIKE <replaceable>parent_table</replaceable> [ <replaceable>like_option</replaceable> ... ] }
27+
| LIKE <replaceable>source_table</replaceable> [ <replaceable>like_option</replaceable> ... ] }
2828
[, ... ]
2929
] )
3030
[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
@@ -312,7 +312,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
312312
</varlistentry>
313313

314314
<varlistentry>
315-
<term><literal>LIKE <replaceable>parent_table</replaceable> [ <replaceable>like_option</replaceable> ... ]</literal></term>
315+
<term><literal>LIKE <replaceable>source_table</replaceable> [ <replaceable>like_option</replaceable> ... ]</literal></term>
316316
<listitem>
317317
<para>
318318
The <literal>LIKE</literal> clause specifies a table from which

src/backend/nodes/copyfuncs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,10 +2727,10 @@ _copyCreateStmt(const CreateStmt *from)
27272727
return newnode;
27282728
}
27292729

2730-
static InhRelation *
2731-
_copyInhRelation(const InhRelation *from)
2730+
static TableLikeClause *
2731+
_copyTableLikeClause(const TableLikeClause *from)
27322732
{
2733-
InhRelation *newnode = makeNode(InhRelation);
2733+
TableLikeClause *newnode = makeNode(TableLikeClause);
27342734

27352735
COPY_NODE_FIELD(relation);
27362736
COPY_SCALAR_FIELD(options);
@@ -4134,8 +4134,8 @@ copyObject(const void *from)
41344134
case T_CreateStmt:
41354135
retval = _copyCreateStmt(from);
41364136
break;
4137-
case T_InhRelation:
4138-
retval = _copyInhRelation(from);
4137+
case T_TableLikeClause:
4138+
retval = _copyTableLikeClause(from);
41394139
break;
41404140
case T_DefineStmt:
41414141
retval = _copyDefineStmt(from);

src/backend/nodes/equalfuncs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ _equalCreateStmt(const CreateStmt *a, const CreateStmt *b)
11601160
}
11611161

11621162
static bool
1163-
_equalInhRelation(const InhRelation *a, const InhRelation *b)
1163+
_equalTableLikeClause(const TableLikeClause *a, const TableLikeClause *b)
11641164
{
11651165
COMPARE_NODE_FIELD(relation);
11661166
COMPARE_SCALAR_FIELD(options);
@@ -2677,8 +2677,8 @@ equal(const void *a, const void *b)
26772677
case T_CreateStmt:
26782678
retval = _equalCreateStmt(a, b);
26792679
break;
2680-
case T_InhRelation:
2681-
retval = _equalInhRelation(a, b);
2680+
case T_TableLikeClause:
2681+
retval = _equalTableLikeClause(a, b);
26822682
break;
26832683
case T_DefineStmt:
26842684
retval = _equalDefineStmt(a, b);

src/backend/nodes/outfuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,9 +2066,9 @@ _outDefElem(StringInfo str, const DefElem *node)
20662066
}
20672067

20682068
static void
2069-
_outInhRelation(StringInfo str, const InhRelation *node)
2069+
_outTableLikeClause(StringInfo str, const TableLikeClause *node)
20702070
{
2071-
WRITE_NODE_TYPE("INHRELATION");
2071+
WRITE_NODE_TYPE("TABLELIKECLAUSE");
20722072

20732073
WRITE_NODE_FIELD(relation);
20742074
WRITE_UINT_FIELD(options);
@@ -3142,8 +3142,8 @@ _outNode(StringInfo str, const void *obj)
31423142
case T_DefElem:
31433143
_outDefElem(str, obj);
31443144
break;
3145-
case T_InhRelation:
3146-
_outInhRelation(str, obj);
3145+
case T_TableLikeClause:
3146+
_outTableLikeClause(str, obj);
31473147
break;
31483148
case T_LockingClause:
31493149
_outLockingClause(str, obj);

src/backend/parser/gram.y

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,18 +2718,10 @@ ConstraintAttr:
27182718
;
27192719

27202720

2721-
/*
2722-
* SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2723-
* This seems to be a poor man's inheritance capability, with the resulting
2724-
* tables completely decoupled except for the original commonality in definitions.
2725-
*
2726-
* This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2727-
* which is a part of SQL:2003.
2728-
*/
27292721
TableLikeClause:
27302722
LIKE qualified_name TableLikeOptionList
27312723
{
2732-
InhRelation *n = makeNode(InhRelation);
2724+
TableLikeClause *n = makeNode(TableLikeClause);
27332725
n->relation = $2;
27342726
n->options = $3;
27352727
$$ = (Node *)n;

src/backend/parser/parse_utilcmd.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ static void transformColumnDefinition(CreateStmtContext *cxt,
102102
ColumnDef *column);
103103
static void transformTableConstraint(CreateStmtContext *cxt,
104104
Constraint *constraint);
105-
static void transformInhRelation(CreateStmtContext *cxt,
106-
InhRelation *inhrelation);
105+
static void transformTableLikeClause(CreateStmtContext *cxt,
106+
TableLikeClause *table_like_clause);
107107
static void transformOfType(CreateStmtContext *cxt,
108108
TypeName *ofTypename);
109109
static char *chooseIndexName(const RangeVar *relation, IndexStmt *index_stmt);
@@ -238,8 +238,8 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
238238
transformTableConstraint(&cxt, (Constraint *) element);
239239
break;
240240

241-
case T_InhRelation:
242-
transformInhRelation(&cxt, (InhRelation *) element);
241+
case T_TableLikeClause:
242+
transformTableLikeClause(&cxt, (TableLikeClause *) element);
243243
break;
244244

245245
default:
@@ -625,14 +625,14 @@ transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
625625
}
626626

627627
/*
628-
* transformInhRelation
628+
* transformTableLikeClause
629629
*
630-
* Change the LIKE <subtable> portion of a CREATE TABLE statement into
630+
* Change the LIKE <srctable> portion of a CREATE TABLE statement into
631631
* column definitions which recreate the user defined column portions of
632-
* <subtable>.
632+
* <srctable>.
633633
*/
634634
static void
635-
transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
635+
transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_clause)
636636
{
637637
AttrNumber parent_attno;
638638
Relation relation;
@@ -641,17 +641,17 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
641641
AclResult aclresult;
642642
char *comment;
643643

644-
relation = parserOpenTable(cxt->pstate, inhRelation->relation,
644+
relation = parserOpenTable(cxt->pstate, table_like_clause->relation,
645645
AccessShareLock);
646646

647647
if (relation->rd_rel->relkind != RELKIND_RELATION)
648648
ereport(ERROR,
649649
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
650-
errmsg("inherited relation \"%s\" is not a table",
651-
inhRelation->relation->relname)));
650+
errmsg("LIKE source relation \"%s\" is not a table",
651+
table_like_clause->relation->relname)));
652652

653653
/*
654-
* Check for SELECT privilages
654+
* Check for SELECT privileges
655655
*/
656656
aclresult = pg_class_aclcheck(RelationGetRelid(relation), GetUserId(),
657657
ACL_SELECT);
@@ -708,7 +708,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
708708
* Copy default, if present and the default has been requested
709709
*/
710710
if (attribute->atthasdef &&
711-
(inhRelation->options & CREATE_TABLE_LIKE_DEFAULTS))
711+
(table_like_clause->options & CREATE_TABLE_LIKE_DEFAULTS))
712712
{
713713
Node *this_default = NULL;
714714
AttrDefault *attrdef;
@@ -736,13 +736,13 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
736736
}
737737

738738
/* Likewise, copy storage if requested */
739-
if (inhRelation->options & CREATE_TABLE_LIKE_STORAGE)
739+
if (table_like_clause->options & CREATE_TABLE_LIKE_STORAGE)
740740
def->storage = attribute->attstorage;
741741
else
742742
def->storage = 0;
743743

744744
/* Likewise, copy comment if requested */
745-
if ((inhRelation->options & CREATE_TABLE_LIKE_COMMENTS) &&
745+
if ((table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS) &&
746746
(comment = GetComment(attribute->attrelid,
747747
RelationRelationId,
748748
attribute->attnum)) != NULL)
@@ -764,7 +764,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
764764
* Copy CHECK constraints if requested, being careful to adjust attribute
765765
* numbers
766766
*/
767-
if ((inhRelation->options & CREATE_TABLE_LIKE_CONSTRAINTS) &&
767+
if ((table_like_clause->options & CREATE_TABLE_LIKE_CONSTRAINTS) &&
768768
tupleDesc->constr)
769769
{
770770
AttrNumber *attmap = varattnos_map_schema(tupleDesc, cxt->columns);
@@ -787,7 +787,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
787787
cxt->ckconstraints = lappend(cxt->ckconstraints, n);
788788

789789
/* Copy comment on constraint */
790-
if ((inhRelation->options & CREATE_TABLE_LIKE_COMMENTS) &&
790+
if ((table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS) &&
791791
(comment = GetComment(get_constraint_oid(RelationGetRelid(relation),
792792
n->conname, false),
793793
ConstraintRelationId,
@@ -810,7 +810,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
810810
/*
811811
* Likewise, copy indexes if requested
812812
*/
813-
if ((inhRelation->options & CREATE_TABLE_LIKE_INDEXES) &&
813+
if ((table_like_clause->options & CREATE_TABLE_LIKE_INDEXES) &&
814814
relation->rd_rel->relhasindex)
815815
{
816816
AttrNumber *attmap = varattnos_map_schema(tupleDesc, cxt->columns);
@@ -831,7 +831,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
831831
index_stmt = generateClonedIndexStmt(cxt, parent_index, attmap);
832832

833833
/* Copy comment on index */
834-
if (inhRelation->options & CREATE_TABLE_LIKE_COMMENTS)
834+
if (table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS)
835835
{
836836
comment = GetComment(parent_index_oid, RelationRelationId, 0);
837837

src/include/nodes/nodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ typedef enum NodeTag
389389
T_FuncWithArgs,
390390
T_AccessPriv,
391391
T_CreateOpClassItem,
392-
T_InhRelation,
392+
T_TableLikeClause,
393393
T_FunctionParameter,
394394
T_LockingClause,
395395
T_RowMarkClause,

src/include/nodes/parsenodes.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,24 +504,24 @@ typedef struct ColumnDef
504504
} ColumnDef;
505505

506506
/*
507-
* inhRelation - Relation a CREATE TABLE is to inherit attributes of
507+
* TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause
508508
*/
509-
typedef struct InhRelation
509+
typedef struct TableLikeClause
510510
{
511511
NodeTag type;
512512
RangeVar *relation;
513-
bits32 options; /* OR of CreateStmtLikeOption flags */
514-
} InhRelation;
513+
bits32 options; /* OR of TableLikeOption flags */
514+
} TableLikeClause;
515515

516-
typedef enum CreateStmtLikeOption
516+
typedef enum TableLikeOption
517517
{
518518
CREATE_TABLE_LIKE_DEFAULTS = 1 << 0,
519519
CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1,
520520
CREATE_TABLE_LIKE_INDEXES = 1 << 2,
521521
CREATE_TABLE_LIKE_STORAGE = 1 << 3,
522522
CREATE_TABLE_LIKE_COMMENTS = 1 << 4,
523523
CREATE_TABLE_LIKE_ALL = 0x7FFFFFFF
524-
} CreateStmtLikeOption;
524+
} TableLikeOption;
525525

526526
/*
527527
* IndexElem - index parameters (used in CREATE INDEX)

0 commit comments

Comments
 (0)