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

Commit38bb77a

Browse files
committed
ALTER TABLE DROP COLUMN works. Patch by Christopher Kings-Lynne,
code review by Tom Lane. Remaining issues: functions that take orreturn tuple types are likely to break if one drops (or adds!)a column in the table defining the type. Need to think about whatto do here.Along the way: some code review for recent COPY changes; mark systemcolumns attnotnull = true where appropriate, per discussion a month ago.
1 parent5e6528a commit38bb77a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1821
-889
lines changed

‎contrib/dblink/dblink.c

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -829,16 +829,18 @@ dblink_replace_text(PG_FUNCTION_ARGS)
829829
left_text=DatumGetTextP(DirectFunctionCall3(text_substr,PointerGetDatum(buf_text),1,DatumGetInt32(DirectFunctionCall2(textpos,PointerGetDatum(buf_text),PointerGetDatum(from_sub_text)))-1));
830830
right_text=DatumGetTextP(DirectFunctionCall3(text_substr,PointerGetDatum(buf_text),DatumGetInt32(DirectFunctionCall2(textpos,PointerGetDatum(buf_text),PointerGetDatum(from_sub_text)))+from_sub_text_len,-1));
831831

832-
appendStringInfo(str,DatumGetCString(DirectFunctionCall1(textout,PointerGetDatum(left_text))));
833-
appendStringInfo(str,to_sub_str);
832+
appendStringInfo(str,"%s",
833+
DatumGetCString(DirectFunctionCall1(textout,PointerGetDatum(left_text))));
834+
appendStringInfo(str,"%s",to_sub_str);
834835

835836
pfree(buf_text);
836837
pfree(left_text);
837838
buf_text=right_text;
838839
curr_posn=DatumGetInt32(DirectFunctionCall2(textpos,PointerGetDatum(buf_text),PointerGetDatum(from_sub_text)));
839840
}
840841

841-
appendStringInfo(str,DatumGetCString(DirectFunctionCall1(textout,PointerGetDatum(buf_text))));
842+
appendStringInfo(str,"%s",
843+
DatumGetCString(DirectFunctionCall1(textout,PointerGetDatum(buf_text))));
842844
pfree(buf_text);
843845

844846
ret_str=pstrdup(str->data);
@@ -1013,10 +1015,11 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
10131015
TupleDesctupdesc;
10141016
intnatts;
10151017
StringInfostr=makeStringInfo();
1016-
char*sql=NULL;
1017-
char*val=NULL;
1018+
char*sql;
1019+
char*val;
10181020
int16key;
1019-
unsignedinti;
1021+
inti;
1022+
boolneedComma;
10201023

10211024
/*
10221025
* Open relation using relid
@@ -1029,22 +1032,33 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
10291032
tuple=get_tuple_of_interest(relid,pkattnums,pknumatts,src_pkattvals);
10301033

10311034
appendStringInfo(str,"INSERT INTO %s(",quote_ident_cstr(relname));
1035+
1036+
needComma= false;
10321037
for (i=0;i<natts;i++)
10331038
{
1034-
if (i>0)
1039+
if (tupdesc->attrs[i]->attisdropped)
1040+
continue;
1041+
1042+
if (needComma)
10351043
appendStringInfo(str,",");
10361044

1037-
appendStringInfo(str,NameStr(tupdesc->attrs[i]->attname));
1045+
appendStringInfo(str,"%s",
1046+
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
1047+
needComma= true;
10381048
}
10391049

10401050
appendStringInfo(str,") VALUES(");
10411051

10421052
/*
10431053
* remember attvals are 1 based
10441054
*/
1055+
needComma= false;
10451056
for (i=0;i<natts;i++)
10461057
{
1047-
if (i>0)
1058+
if (tupdesc->attrs[i]->attisdropped)
1059+
continue;
1060+
1061+
if (needComma)
10481062
appendStringInfo(str,",");
10491063

10501064
if (tgt_pkattvals!=NULL)
@@ -1059,11 +1073,12 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
10591073

10601074
if (val!=NULL)
10611075
{
1062-
appendStringInfo(str,quote_literal_cstr(val));
1076+
appendStringInfo(str,"%s",quote_literal_cstr(val));
10631077
pfree(val);
10641078
}
10651079
else
10661080
appendStringInfo(str,"NULL");
1081+
needComma= true;
10671082
}
10681083
appendStringInfo(str,")");
10691084

@@ -1083,9 +1098,9 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval
10831098
TupleDesctupdesc;
10841099
intnatts;
10851100
StringInfostr=makeStringInfo();
1086-
char*sql=NULL;
1087-
char*val=NULL;
1088-
unsignedinti;
1101+
char*sql;
1102+
char*val;
1103+
inti;
10891104

10901105
/*
10911106
* Open relation using relid
@@ -1103,21 +1118,24 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval
11031118
if (i>0)
11041119
appendStringInfo(str," AND ");
11051120

1106-
appendStringInfo(str,NameStr(tupdesc->attrs[pkattnum-1]->attname));
1121+
appendStringInfo(str,"%s",
1122+
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum-1]->attname)));
11071123

11081124
if (tgt_pkattvals!=NULL)
11091125
val=pstrdup(tgt_pkattvals[i]);
11101126
else
1127+
{
11111128
elog(ERROR,"Target key array must not be NULL");
1129+
val=NULL;/* keep compiler quiet */
1130+
}
11121131

11131132
if (val!=NULL)
11141133
{
1115-
appendStringInfo(str,"=");
1116-
appendStringInfo(str,quote_literal_cstr(val));
1134+
appendStringInfo(str," = %s",quote_literal_cstr(val));
11171135
pfree(val);
11181136
}
11191137
else
1120-
appendStringInfo(str,"IS NULL");
1138+
appendStringInfo(str,"IS NULL");
11211139
}
11221140

11231141
sql=pstrdup(str->data);
@@ -1137,10 +1155,11 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
11371155
TupleDesctupdesc;
11381156
intnatts;
11391157
StringInfostr=makeStringInfo();
1140-
char*sql=NULL;
1141-
char*val=NULL;
1158+
char*sql;
1159+
char*val;
11421160
int16key;
11431161
inti;
1162+
boolneedComma;
11441163

11451164
/*
11461165
* Open relation using relid
@@ -1154,13 +1173,17 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
11541173

11551174
appendStringInfo(str,"UPDATE %s SET ",quote_ident_cstr(relname));
11561175

1176+
needComma= false;
11571177
for (i=0;i<natts;i++)
11581178
{
1159-
if (i>0)
1160-
appendStringInfo(str,",");
1179+
if (tupdesc->attrs[i]->attisdropped)
1180+
continue;
1181+
1182+
if (needComma)
1183+
appendStringInfo(str,", ");
11611184

1162-
appendStringInfo(str,NameStr(tupdesc->attrs[i]->attname));
1163-
appendStringInfo(str,"=");
1185+
appendStringInfo(str,"%s = ",
1186+
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
11641187

11651188
if (tgt_pkattvals!=NULL)
11661189
key=get_attnum_pk_pos(pkattnums,pknumatts,i+1);
@@ -1174,11 +1197,12 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
11741197

11751198
if (val!=NULL)
11761199
{
1177-
appendStringInfo(str,quote_literal_cstr(val));
1200+
appendStringInfo(str,"%s",quote_literal_cstr(val));
11781201
pfree(val);
11791202
}
11801203
else
11811204
appendStringInfo(str,"NULL");
1205+
needComma= true;
11821206
}
11831207

11841208
appendStringInfo(str," WHERE ");
@@ -1190,7 +1214,8 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
11901214
if (i>0)
11911215
appendStringInfo(str," AND ");
11921216

1193-
appendStringInfo(str,NameStr(tupdesc->attrs[pkattnum-1]->attname));
1217+
appendStringInfo(str,"%s",
1218+
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum-1]->attname)));
11941219

11951220
if (tgt_pkattvals!=NULL)
11961221
val=pstrdup(tgt_pkattvals[i]);
@@ -1199,12 +1224,11 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
11991224

12001225
if (val!=NULL)
12011226
{
1202-
appendStringInfo(str,"=");
1203-
appendStringInfo(str,quote_literal_cstr(val));
1227+
appendStringInfo(str," = %s",quote_literal_cstr(val));
12041228
pfree(val);
12051229
}
12061230
else
1207-
appendStringInfo(str,"IS NULL");
1231+
appendStringInfo(str,"IS NULL");
12081232
}
12091233

12101234
sql=pstrdup(str->data);
@@ -1297,7 +1321,7 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p
12971321
* Build sql statement to look up tuple of interest
12981322
* Use src_pkattvals as the criteria.
12991323
*/
1300-
appendStringInfo(str,"SELECT *from %s WHERE ",relname);
1324+
appendStringInfo(str,"SELECT *FROM %s WHERE ",quote_ident_cstr(relname));
13011325

13021326
for (i=0;i<pknumatts;i++)
13031327
{
@@ -1306,17 +1330,17 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p
13061330
if (i>0)
13071331
appendStringInfo(str," AND ");
13081332

1309-
appendStringInfo(str,NameStr(tupdesc->attrs[pkattnum-1]->attname));
1333+
appendStringInfo(str,"%s",
1334+
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum-1]->attname)));
13101335

13111336
val=pstrdup(src_pkattvals[i]);
13121337
if (val!=NULL)
13131338
{
1314-
appendStringInfo(str,"=");
1315-
appendStringInfo(str,quote_literal_cstr(val));
1339+
appendStringInfo(str," = %s",quote_literal_cstr(val));
13161340
pfree(val);
13171341
}
13181342
else
1319-
appendStringInfo(str,"IS NULL");
1343+
appendStringInfo(str,"IS NULL");
13201344
}
13211345

13221346
sql=pstrdup(str->data);

‎doc/src/sgml/catalogs.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.50 2002/07/31 17:19:49 tgl Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.51 2002/08/02 18:15:04 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -810,6 +810,17 @@
810810
</entry>
811811
</row>
812812

813+
<row>
814+
<entry>attisdropped</entry>
815+
<entry><type>bool</type></entry>
816+
<entry></entry>
817+
<entry>
818+
This column has been dropped and is no longer valid. A dropped
819+
column is still physically present in the table, but is
820+
ignored by the parser and so cannot be accessed via SQL.
821+
</entry>
822+
</row>
823+
813824
</tbody>
814825
</tgroup>
815826
</table>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp