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

Commit 1fa9241

Browse files
committed
Make more use of makeColumnDef()
Since we already have it, we might as well make full use of it, instead of assembling ColumnDef by hand in several places. Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://www.postgresql.org/message-id/flat/52a125e4-ff9a-95f5-9f61-b87cf447e4da@eisentraut.org
1 parent 2b088c8 commit 1fa9241

File tree

3 files changed

+19
-65
lines changed

3 files changed

+19
-65
lines changed

src/backend/commands/sequence.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,40 +172,27 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
172172
stmt->tableElts = NIL;
173173
for (i = SEQ_COL_FIRSTCOL; i <= SEQ_COL_LASTCOL; i++)
174174
{
175-
ColumnDef *coldef = makeNode(ColumnDef);
176-
177-
coldef->inhcount = 0;
178-
coldef->is_local = true;
179-
coldef->is_not_null = true;
180-
coldef->is_from_type = false;
181-
coldef->storage = 0;
182-
coldef->raw_default = NULL;
183-
coldef->cooked_default = NULL;
184-
coldef->collClause = NULL;
185-
coldef->collOid = InvalidOid;
186-
coldef->constraints = NIL;
187-
coldef->location = -1;
188-
189-
null[i - 1] = false;
175+
ColumnDef *coldef;
190176

191177
switch (i)
192178
{
193179
case SEQ_COL_LASTVAL:
194-
coldef->typeName = makeTypeNameFromOid(INT8OID, -1);
195-
coldef->colname = "last_value";
180+
coldef = makeColumnDef("last_value", INT8OID, -1, InvalidOid);
196181
value[i - 1] = Int64GetDatumFast(seqdataform.last_value);
197182
break;
198183
case SEQ_COL_LOG:
199-
coldef->typeName = makeTypeNameFromOid(INT8OID, -1);
200-
coldef->colname = "log_cnt";
184+
coldef = makeColumnDef("log_cnt", INT8OID, -1, InvalidOid);
201185
value[i - 1] = Int64GetDatum((int64) 0);
202186
break;
203187
case SEQ_COL_CALLED:
204-
coldef->typeName = makeTypeNameFromOid(BOOLOID, -1);
205-
coldef->colname = "is_called";
188+
coldef = makeColumnDef("is_called", BOOLOID, -1, InvalidOid);
206189
value[i - 1] = BoolGetDatum(false);
207190
break;
208191
}
192+
193+
coldef->is_not_null = true;
194+
null[i - 1] = false;
195+
209196
stmt->tableElts = lappend(stmt->tableElts, coldef);
210197
}
211198

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,31 +2755,20 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
27552755
/*
27562756
* No, create a new inherited column
27572757
*/
2758-
def = makeNode(ColumnDef);
2759-
def->colname = pstrdup(attributeName);
2760-
def->typeName = makeTypeNameFromOid(attribute->atttypid,
2761-
attribute->atttypmod);
2758+
def = makeColumnDef(attributeName, attribute->atttypid,
2759+
attribute->atttypmod, attribute->attcollation);
27622760
def->inhcount = 1;
27632761
def->is_local = false;
27642762
/* mark attnotnull if parent has it and it's not NO INHERIT */
27652763
if (bms_is_member(parent_attno, nncols) ||
27662764
bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
27672765
pkattrs))
27682766
def->is_not_null = true;
2769-
def->is_from_type = false;
27702767
def->storage = attribute->attstorage;
2771-
def->raw_default = NULL;
2772-
def->cooked_default = NULL;
27732768
def->generated = attribute->attgenerated;
2774-
def->collClause = NULL;
2775-
def->collOid = attribute->attcollation;
2776-
def->constraints = NIL;
2777-
def->location = -1;
27782769
if (CompressionMethodIsValid(attribute->attcompression))
27792770
def->compression =
27802771
pstrdup(GetCompressionMethodName(attribute->attcompression));
2781-
else
2782-
def->compression = NULL;
27832772
inhSchema = lappend(inhSchema, def);
27842773
newattmap->attnums[parent_attno - 1] = ++child_attno;
27852774

src/backend/parser/parse_utilcmd.c

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,6 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
10661066
{
10671067
Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
10681068
parent_attno - 1);
1069-
char *attributeName = NameStr(attribute->attname);
10701069
ColumnDef *def;
10711070

10721071
/*
@@ -1076,29 +1075,18 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
10761075
continue;
10771076

10781077
/*
1079-
* Create a new column, which is marked as NOT inherited.
1080-
*
1078+
* Create a new column definition
1079+
*/
1080+
def = makeColumnDef(NameStr(attribute->attname), attribute->atttypid,
1081+
attribute->atttypmod, attribute->attcollation);
1082+
1083+
/*
10811084
* For constraints, ONLY the not-null constraint is inherited by the
10821085
* new column definition per SQL99; however we cannot do that
10831086
* correctly here, so we leave it for expandTableLikeClause to handle.
10841087
*/
1085-
def = makeNode(ColumnDef);
1086-
def->colname = pstrdup(attributeName);
1087-
def->typeName = makeTypeNameFromOid(attribute->atttypid,
1088-
attribute->atttypmod);
1089-
def->inhcount = 0;
1090-
def->is_local = true;
1091-
def->is_not_null = false;
10921088
if (attribute->attnotnull)
10931089
process_notnull_constraints = true;
1094-
def->is_from_type = false;
1095-
def->storage = 0;
1096-
def->raw_default = NULL;
1097-
def->cooked_default = NULL;
1098-
def->collClause = NULL;
1099-
def->collOid = attribute->attcollation;
1100-
def->constraints = NIL;
1101-
def->location = -1;
11021090

11031091
/*
11041092
* Add to column list
@@ -1635,20 +1623,10 @@ transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
16351623
if (attr->attisdropped)
16361624
continue;
16371625

1638-
n = makeNode(ColumnDef);
1639-
n->colname = pstrdup(NameStr(attr->attname));
1640-
n->typeName = makeTypeNameFromOid(attr->atttypid, attr->atttypmod);
1641-
n->inhcount = 0;
1642-
n->is_local = true;
1643-
n->is_not_null = false;
1626+
n = makeColumnDef(NameStr(attr->attname), attr->atttypid,
1627+
attr->atttypmod, attr->attcollation);
16441628
n->is_from_type = true;
1645-
n->storage = 0;
1646-
n->raw_default = NULL;
1647-
n->cooked_default = NULL;
1648-
n->collClause = NULL;
1649-
n->collOid = attr->attcollation;
1650-
n->constraints = NIL;
1651-
n->location = -1;
1629+
16521630
cxt->columns = lappend(cxt->columns, n);
16531631
}
16541632
ReleaseTupleDesc(tupdesc);

0 commit comments

Comments
 (0)