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

Commit691dc28

Browse files
committed
Fix for SELECT INTO TABLE for varchar().
1 parent8169769 commit691dc28

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

‎src/backend/executor/execMain.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.39 1998/01/16 23:19:49 momjian Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.40 1998/01/19 02:37:32 momjian Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -563,6 +563,8 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
563563
*/
564564
tupdesc=CreateTupleDescCopy(tupType);
565565

566+
setAtttypmodForCreateTable(tupdesc,targetList,rangeTable);
567+
566568
intoRelationId=heap_create_with_catalog(intoName,tupdesc);
567569

568570
FreeTupleDesc(tupdesc);

‎src/backend/executor/execUtils.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.24 1998/01/16 23:19:52 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.25 1998/01/19 02:37:33 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1177,3 +1177,50 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
11771177
if (econtext!=NULL)
11781178
pfree(econtext);
11791179
}
1180+
1181+
/* ----------------------------------------------------------------
1182+
* setAtttyplenForCreateTable -
1183+
* called when we do a SELECT * INTO TABLE tab
1184+
* needed for attributes that have atttypmod like bpchar and
1185+
* varchar
1186+
* ----------------------------------------------------------------
1187+
*/
1188+
void
1189+
setAtttypmodForCreateTable(TupleDesctupType,List*targetList,
1190+
List*rangeTable)
1191+
{
1192+
List*tl;
1193+
TargetEntry*tle;
1194+
Node*expr;
1195+
intvarno;
1196+
1197+
tl=targetList;
1198+
1199+
for (varno=0;varno<tupType->natts;varno++)
1200+
{
1201+
tle=lfirst(tl);
1202+
1203+
if (USE_ATTTYPMOD(tupType->attrs[varno]->atttypid))
1204+
{
1205+
expr=tle->expr;
1206+
if (expr&&IsA(expr,Var))
1207+
{
1208+
Var*var;
1209+
RangeTblEntry*rtentry;
1210+
Relationrd;
1211+
1212+
var= (Var*)expr;
1213+
rtentry=rt_fetch(var->varnoold,rangeTable);
1214+
rd=heap_open(rtentry->relid);
1215+
/* set length to that defined in relation */
1216+
tupType->attrs[varno]->atttypmod=
1217+
(*rd->rd_att->attrs[var->varoattno-1]).atttypmod;
1218+
heap_close(rd);
1219+
}
1220+
else
1221+
elog(ERROR,"setAtttypmodForCreateTable: can't get atttypmod for field (for length, etc.)");
1222+
}
1223+
tl=lnext(tl);
1224+
}
1225+
}
1226+

‎src/include/catalog/pg_attribute.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_attribute.h,v 1.22 1998/01/16 23:20:49 momjian Exp $
10+
* $Id: pg_attribute.h,v 1.23 1998/01/19 02:37:45 momjian Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -89,6 +89,14 @@ CATALOG(pg_attribute) BOOTSTRAP
8989
/*
9090
* atttypmod records type-specific modifications supplied at table
9191
* creation time.
92+
* This is not integrated into all areas of the source. It is in
93+
* TypeName to pass typmod info from the parser during table creation
94+
* time, and it is used in the parser when converting a string to a
95+
* typed constant associated with a variable. We also have a hack in
96+
* execMain.c/execUtils.c that uses atttypmod to properly create tables
97+
* for SELECT * INTO TABLE test2 FROM test;
98+
* One day, we may add this to Resdom, and pass it through all areas.
99+
* 1998/1/18 bjm
92100
*/
93101

94102
boolattbyval;

‎src/include/catalog/pg_type.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_type.h,v 1.26 1997/11/26 04:50:47 momjian Exp $
10+
* $Id: pg_type.h,v 1.27 1998/01/19 02:37:47 momjian Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -364,6 +364,9 @@ DATA(insert OID = 1296 ( timestamp PGUID4 19 t b t \054 00 timestamp_in time
364364
DESCR("limited-range ISO-format date and time");
365365
#defineTIMESTAMPOID1296
366366

367+
368+
#defineUSE_ATTTYPMOD(typeid)((typeid) == BPCHAROID || (typeid) == VARCHAROID)
369+
367370
/*
368371
* prototypes for functions in pg_type.c
369372
*/

‎src/include/executor/executor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: executor.h,v 1.17 1998/01/14 15:48:43 momjian Exp $
9+
* $Id: executor.h,v 1.18 1998/01/19 02:37:51 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -120,6 +120,8 @@ extern TupleDesc ExecTypeFromTL(List *targetList);
120120
externvoidResetTupleCount(void);
121121
externvoidExecAssignNodeBaseInfo(EState*estate,CommonState*basenode,
122122
Plan*parent);
123+
externvoidsetAtttypmodForCreateTable(TupleDesctupType,List*targetList,
124+
List*rangeTable);
123125
externvoidExecAssignExprContext(EState*estate,CommonState*commonstate);
124126
externvoidExecAssignResultType(CommonState*commonstate,
125127
TupleDesctupDesc);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp