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

Commitf9e6e27

Browse files
committed
Break transformCreateStmt() into multiple routines and make
transformAlterStmt() use these routines, instead of having lots ofduplicate (not to mention should-have-been-duplicate) code.Adding a column with a CHECK constraint actually works now,and the tests to reject unsupported DEFAULT and NOT NULL clausesactually fire now. ALTER TABLE ADD PRIMARY KEY works, modulohaving to have created the column(s) NOT NULL already.
1 parente98476e commitf9e6e27

File tree

9 files changed

+1118
-1173
lines changed

9 files changed

+1118
-1173
lines changed

‎doc/src/sgml/ref/alter_table.sgml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.28 2001/09/1202:13:25 ishii Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.29 2001/10/1200:07:14 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -24,8 +24,7 @@ Postgres documentation
2424
</refsynopsisdivinfo>
2525
<synopsis>
2626
ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
27-
ADD [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> <replaceable
28-
class="PARAMETER">type</replaceable>
27+
ADD [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> <replaceable class="PARAMETER">type</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
2928
ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ * ]
3029
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> { SET DEFAULT <replaceable
3130
class="PARAMETER">value</replaceable> | DROP DEFAULT }
@@ -202,21 +201,14 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
202201

203202
<para>
204203
In the current implementation of <literal>ADD COLUMN</literal>,
205-
default andconstraintclauses for the
206-
new column will be ignored.You can use the <literal>SET DEFAULT</literal>
207-
formof <command>ALTER TABLE</command> to set the default later.
204+
default andNOT NULLclauses for the new column are not supported.
205+
You can use the <literal>SET DEFAULT</literal> form
206+
of <command>ALTER TABLE</command> to set the default later.
208207
(You may also want to update the already existing rows to the
209208
new default value, using <xref linkend="sql-update"
210209
endterm="sql-update-title">.)
211210
</para>
212211

213-
<para>
214-
In the current implementation, only UNIQUE, FOREIGN KEY and CHECK constraints can
215-
be added to a table. To create a primary constraint, create
216-
a unique, not null index (see <xref linkend="SQL-CREATEINDEX"
217-
endterm="SQL-CREATEINDEX-title">).
218-
</para>
219-
220212
<para>
221213
Currently only CHECK constraints can be dropped from a table. The RESTRICT
222214
keyword is required, although dependencies are not checked. The CASCADE
@@ -318,7 +310,7 @@ ALTER TABLE distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, zip
318310
<title>SQL92</title>
319311
<para>
320312
The <literal>ADD COLUMN</literal> form is compliant with the exception that
321-
it does not support defaults and constraints, as explained above.
313+
it does not support defaults andNOT NULLconstraints, as explained above.
322314
The <literal>ALTER COLUMN</literal> form is in full compliance.
323315
</para>
324316

‎src/backend/catalog/pg_type.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.63 2001/09/06 02:07:42 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.64 2001/10/12 00:07:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -555,20 +555,17 @@ TypeRename(const char *oldTypeName, const char *newTypeName)
555555
* makeArrayTypeName(typeName);
556556
* - given a base type name, make an array of type name out of it
557557
*
558-
* theCALLER is responsible for pfreeing the
558+
* thecaller is responsible for pfreeing the result
559559
*/
560-
561560
char*
562561
makeArrayTypeName(char*typeName)
563562
{
564563
char*arr;
565564

566565
if (!typeName)
567566
returnNULL;
568-
arr=palloc(strlen(typeName)+2);
569-
arr[0]='_';
570-
strcpy(arr+1,typeName);
571-
567+
arr=palloc(NAMEDATALEN);
568+
snprintf(arr,NAMEDATALEN,
569+
"_%.*s",NAMEDATALEN-2,typeName);
572570
returnarr;
573-
574571
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp