summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorPeter Eisentraut2012-01-07 12:58:13 +0000
committerPeter Eisentraut2012-01-07 21:02:33 +0000
commitdb49517c62750322fb2a37ff6324ecc00965e641 (patch)
tree6ebb1b135e88ee634f529faf237af2034ee926ca /src/backend
parent0a41e865845bfa5d7aafcc5fe000dafa26573fef (diff)
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.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/nodes/copyfuncs.c10
-rw-r--r--src/backend/nodes/equalfuncs.c6
-rw-r--r--src/backend/nodes/outfuncs.c8
-rw-r--r--src/backend/parser/gram.y10
-rw-r--r--src/backend/parser/parse_utilcmd.c38
5 files changed, 32 insertions, 40 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 756e3a689b8..71da0d8564b 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -2727,10 +2727,10 @@ _copyCreateStmt(const CreateStmt *from)
return newnode;
}
-static InhRelation *
-_copyInhRelation(const InhRelation *from)
+static TableLikeClause *
+_copyTableLikeClause(const TableLikeClause *from)
{
- InhRelation *newnode = makeNode(InhRelation);
+ TableLikeClause *newnode = makeNode(TableLikeClause);
COPY_NODE_FIELD(relation);
COPY_SCALAR_FIELD(options);
@@ -4134,8 +4134,8 @@ copyObject(const void *from)
case T_CreateStmt:
retval = _copyCreateStmt(from);
break;
- case T_InhRelation:
- retval = _copyInhRelation(from);
+ case T_TableLikeClause:
+ retval = _copyTableLikeClause(from);
break;
case T_DefineStmt:
retval = _copyDefineStmt(from);
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index 9eff42f707e..ba949db91f2 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -1160,7 +1160,7 @@ _equalCreateStmt(const CreateStmt *a, const CreateStmt *b)
}
static bool
-_equalInhRelation(const InhRelation *a, const InhRelation *b)
+_equalTableLikeClause(const TableLikeClause *a, const TableLikeClause *b)
{
COMPARE_NODE_FIELD(relation);
COMPARE_SCALAR_FIELD(options);
@@ -2677,8 +2677,8 @@ equal(const void *a, const void *b)
case T_CreateStmt:
retval = _equalCreateStmt(a, b);
break;
- case T_InhRelation:
- retval = _equalInhRelation(a, b);
+ case T_TableLikeClause:
+ retval = _equalTableLikeClause(a, b);
break;
case T_DefineStmt:
retval = _equalDefineStmt(a, b);
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index cb94614821d..8bc19478357 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -2066,9 +2066,9 @@ _outDefElem(StringInfo str, const DefElem *node)
}
static void
-_outInhRelation(StringInfo str, const InhRelation *node)
+_outTableLikeClause(StringInfo str, const TableLikeClause *node)
{
- WRITE_NODE_TYPE("INHRELATION");
+ WRITE_NODE_TYPE("TABLELIKECLAUSE");
WRITE_NODE_FIELD(relation);
WRITE_UINT_FIELD(options);
@@ -3142,8 +3142,8 @@ _outNode(StringInfo str, const void *obj)
case T_DefElem:
_outDefElem(str, obj);
break;
- case T_InhRelation:
- _outInhRelation(str, obj);
+ case T_TableLikeClause:
+ _outTableLikeClause(str, obj);
break;
case T_LockingClause:
_outLockingClause(str, obj);
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 87d7305c762..0ec039b9a96 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2718,18 +2718,10 @@ ConstraintAttr:
;
-/*
- * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
- * This seems to be a poor man's inheritance capability, with the resulting
- * tables completely decoupled except for the original commonality in definitions.
- *
- * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
- * which is a part of SQL:2003.
- */
TableLikeClause:
LIKE qualified_name TableLikeOptionList
{
- InhRelation *n = makeNode(InhRelation);
+ TableLikeClause *n = makeNode(TableLikeClause);
n->relation = $2;
n->options = $3;
$$ = (Node *)n;
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 19ccf9914e5..e14ae09e6f9 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -102,8 +102,8 @@ static void transformColumnDefinition(CreateStmtContext *cxt,
ColumnDef *column);
static void transformTableConstraint(CreateStmtContext *cxt,
Constraint *constraint);
-static void transformInhRelation(CreateStmtContext *cxt,
- InhRelation *inhrelation);
+static void transformTableLikeClause(CreateStmtContext *cxt,
+ TableLikeClause *table_like_clause);
static void transformOfType(CreateStmtContext *cxt,
TypeName *ofTypename);
static char *chooseIndexName(const RangeVar *relation, IndexStmt *index_stmt);
@@ -238,8 +238,8 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
transformTableConstraint(&cxt, (Constraint *) element);
break;
- case T_InhRelation:
- transformInhRelation(&cxt, (InhRelation *) element);
+ case T_TableLikeClause:
+ transformTableLikeClause(&cxt, (TableLikeClause *) element);
break;
default:
@@ -625,14 +625,14 @@ transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
}
/*
- * transformInhRelation
+ * transformTableLikeClause
*
- * Change the LIKE <subtable> portion of a CREATE TABLE statement into
+ * Change the LIKE <srctable> portion of a CREATE TABLE statement into
* column definitions which recreate the user defined column portions of
- * <subtable>.
+ * <srctable>.
*/
static void
-transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
+transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_clause)
{
AttrNumber parent_attno;
Relation relation;
@@ -641,17 +641,17 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
AclResult aclresult;
char *comment;
- relation = parserOpenTable(cxt->pstate, inhRelation->relation,
+ relation = parserOpenTable(cxt->pstate, table_like_clause->relation,
AccessShareLock);
if (relation->rd_rel->relkind != RELKIND_RELATION)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("inherited relation \"%s\" is not a table",
- inhRelation->relation->relname)));
+ errmsg("LIKE source relation \"%s\" is not a table",
+ table_like_clause->relation->relname)));
/*
- * Check for SELECT privilages
+ * Check for SELECT privileges
*/
aclresult = pg_class_aclcheck(RelationGetRelid(relation), GetUserId(),
ACL_SELECT);
@@ -708,7 +708,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
* Copy default, if present and the default has been requested
*/
if (attribute->atthasdef &&
- (inhRelation->options & CREATE_TABLE_LIKE_DEFAULTS))
+ (table_like_clause->options & CREATE_TABLE_LIKE_DEFAULTS))
{
Node *this_default = NULL;
AttrDefault *attrdef;
@@ -736,13 +736,13 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
}
/* Likewise, copy storage if requested */
- if (inhRelation->options & CREATE_TABLE_LIKE_STORAGE)
+ if (table_like_clause->options & CREATE_TABLE_LIKE_STORAGE)
def->storage = attribute->attstorage;
else
def->storage = 0;
/* Likewise, copy comment if requested */
- if ((inhRelation->options & CREATE_TABLE_LIKE_COMMENTS) &&
+ if ((table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS) &&
(comment = GetComment(attribute->attrelid,
RelationRelationId,
attribute->attnum)) != NULL)
@@ -764,7 +764,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
* Copy CHECK constraints if requested, being careful to adjust attribute
* numbers
*/
- if ((inhRelation->options & CREATE_TABLE_LIKE_CONSTRAINTS) &&
+ if ((table_like_clause->options & CREATE_TABLE_LIKE_CONSTRAINTS) &&
tupleDesc->constr)
{
AttrNumber *attmap = varattnos_map_schema(tupleDesc, cxt->columns);
@@ -787,7 +787,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
cxt->ckconstraints = lappend(cxt->ckconstraints, n);
/* Copy comment on constraint */
- if ((inhRelation->options & CREATE_TABLE_LIKE_COMMENTS) &&
+ if ((table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS) &&
(comment = GetComment(get_constraint_oid(RelationGetRelid(relation),
n->conname, false),
ConstraintRelationId,
@@ -810,7 +810,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
/*
* Likewise, copy indexes if requested
*/
- if ((inhRelation->options & CREATE_TABLE_LIKE_INDEXES) &&
+ if ((table_like_clause->options & CREATE_TABLE_LIKE_INDEXES) &&
relation->rd_rel->relhasindex)
{
AttrNumber *attmap = varattnos_map_schema(tupleDesc, cxt->columns);
@@ -831,7 +831,7 @@ transformInhRelation(CreateStmtContext *cxt, InhRelation *inhRelation)
index_stmt = generateClonedIndexStmt(cxt, parent_index, attmap);
/* Copy comment on index */
- if (inhRelation->options & CREATE_TABLE_LIKE_COMMENTS)
+ if (table_like_clause->options & CREATE_TABLE_LIKE_COMMENTS)
{
comment = GetComment(parent_index_oid, RelationRelationId, 0);