Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteabc714

Browse files
committed
Reimplement parsing and storage of default expressions and constraint
expressions in CREATE TABLE. There is no longer an emasculated expressionsyntax for these things; it's full a_expr for constraints, and b_exprfor defaults (unfortunately the fact that NOT NULL is a part of thecolumn constraint syntax causes a shift/reduce conflict if you try a_expr.Oh well --- at least parenthesized boolean expressions work now). Also,stored expression for a column default is not pre-coerced to the columntype; we rely on transformInsertStatement to do that when the default isactually used. This means "f1 datetime default 'now'" behaves the waypeople usually expect it to.BTW, all the support code is now there to implement ALTER TABLE ADDCONSTRAINT and ALTER TABLE ADD COLUMN with a default value. I didn'tactually teach ALTER TABLE to call it, but it wouldn't be much work.
1 parentf29ccc8 commiteabc714

File tree

18 files changed

+923
-886
lines changed

18 files changed

+923
-886
lines changed

‎src/backend/access/common/tupdesc.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.54 1999/07/17 20:16:36 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.55 1999/10/03 23:55:25 tgl Exp $
1111
*
1212
* NOTES
1313
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -160,8 +160,6 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
160160
{
161161
if (constr->defval[i].adbin)
162162
cpy->defval[i].adbin=pstrdup(constr->defval[i].adbin);
163-
if (constr->defval[i].adsrc)
164-
cpy->defval[i].adsrc=pstrdup(constr->defval[i].adsrc);
165163
}
166164
}
167165

@@ -175,8 +173,6 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
175173
cpy->check[i].ccname=pstrdup(constr->check[i].ccname);
176174
if (constr->check[i].ccbin)
177175
cpy->check[i].ccbin=pstrdup(constr->check[i].ccbin);
178-
if (constr->check[i].ccsrc)
179-
cpy->check[i].ccsrc=pstrdup(constr->check[i].ccsrc);
180176
}
181177
}
182178

@@ -206,8 +202,6 @@ FreeTupleDesc(TupleDesc tupdesc)
206202
{
207203
if (attrdef[i].adbin)
208204
pfree(attrdef[i].adbin);
209-
if (attrdef[i].adsrc)
210-
pfree(attrdef[i].adsrc);
211205
}
212206
pfree(attrdef);
213207
}
@@ -221,8 +215,6 @@ FreeTupleDesc(TupleDesc tupdesc)
221215
pfree(check[i].ccname);
222216
if (check[i].ccbin)
223217
pfree(check[i].ccbin);
224-
if (check[i].ccsrc)
225-
pfree(check[i].ccsrc);
226218
}
227219
pfree(check);
228220
}
@@ -438,7 +430,7 @@ BuildDescForRelation(List *schema, char *relname)
438430
AttrDefault*attrdef=NULL;
439431
TupleConstr*constr= (TupleConstr*)palloc(sizeof(TupleConstr));
440432
char*attname;
441-
char*typename;
433+
chartypename[NAMEDATALEN];
442434
int32atttypmod;
443435
intattdim;
444436
intndef=0;
@@ -454,11 +446,9 @@ BuildDescForRelation(List *schema, char *relname)
454446

455447
attnum=0;
456448

457-
typename=palloc(NAMEDATALEN);
458-
459449
foreach(p,schema)
460450
{
461-
ColumnDef*entry;
451+
ColumnDef*entry=lfirst(p);
462452
List*arry;
463453

464454
/* ----------------
@@ -469,7 +459,6 @@ BuildDescForRelation(List *schema, char *relname)
469459
*/
470460
attnum++;
471461

472-
entry=lfirst(p);
473462
attname=entry->colname;
474463
arry=entry->typename->arrayBounds;
475464
attisset=entry->typename->setof;
@@ -513,13 +502,15 @@ BuildDescForRelation(List *schema, char *relname)
513502
constr->has_not_null= true;
514503
desc->attrs[attnum-1]->attnotnull=entry->is_not_null;
515504

516-
if (entry->defval!=NULL)
505+
/* Note we copy only pre-cooked default expressions.
506+
* Digestion of raw ones is someone else's problem.
507+
*/
508+
if (entry->cooked_default!=NULL)
517509
{
518510
if (attrdef==NULL)
519511
attrdef= (AttrDefault*)palloc(natts*sizeof(AttrDefault));
520512
attrdef[ndef].adnum=attnum;
521-
attrdef[ndef].adbin=NULL;
522-
attrdef[ndef].adsrc=entry->defval;
513+
attrdef[ndef].adbin=pstrdup(entry->cooked_default);
523514
ndef++;
524515
desc->attrs[attnum-1]->atthasdef= true;
525516
}
@@ -539,7 +530,11 @@ BuildDescForRelation(List *schema, char *relname)
539530
constr->num_defval=ndef;
540531
}
541532
else
533+
{
534+
constr->defval=NULL;
542535
constr->num_defval=0;
536+
}
537+
constr->check=NULL;
543538
constr->num_check=0;
544539
}
545540
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp