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

Commit455891b

Browse files
committed
Code review for UPDATE tab SET col = DEFAULT patch ... whack it around
so it has some chance of working in rules ...
1 parent7b1885b commit455891b

File tree

15 files changed

+186
-114
lines changed

15 files changed

+186
-114
lines changed

‎doc/src/sgml/ref/insert.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/insert.sgml,v 1.22 2003/04/26 23:56:51 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/insert.sgml,v 1.23 2003/07/03 16:32:03 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -33,7 +33,7 @@ INSERT INTO <replaceable class="PARAMETER">table</replaceable> [ ( <replaceable
3333
<para>
3434
The columns in the target list may be listed in any order.
3535
Each column not present in the target list will be inserted
36-
using a default value, eithera declared default value
36+
using a default value, eitherits declared default value
3737
or null.
3838
</para>
3939

@@ -77,7 +77,7 @@ INSERT INTO <replaceable class="PARAMETER">table</replaceable> [ ( <replaceable
7777
<term><literal>DEFAULT VALUES</literal></term>
7878
<listitem>
7979
<para>
80-
All columns will be filled their default values.
80+
All columns will be filledwiththeir default values.
8181
</para>
8282
</listitem>
8383
</varlistentry>

‎doc/src/sgml/ref/update.sgml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v 1.22 2003/06/25 04:19:24 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v 1.23 2003/07/03 16:32:12 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -28,7 +28,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
2828
<para>
2929
<command>UPDATE</command> changes the values of the specified
3030
columns in all rows that satisfy the condition. Only the columns to
31-
be modified need appear as columns in the statement.
31+
be modified need be mentioned in the statement; columns not explicitly
32+
<literal>SET</> retain their previous values.
3233
</para>
3334

3435
<para>
@@ -41,8 +42,9 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
4142
<para>
4243
You must have the <literal>UPDATE</literal> privilege on the table
4344
to update it, as well as the <literal>SELECT</literal>
44-
privilege to any table whose values are read in the <replaceable
45-
class="parameter">condition</replaceable>.
45+
privilege to any table whose values are read in the
46+
<replaceable class="parameter">expression</replaceable>s or
47+
<replaceable class="parameter">condition</replaceable>.
4648
</para>
4749
</refsect1>
4850

@@ -72,7 +74,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
7274
<term><replaceable class="PARAMETER">expression</replaceable></term>
7375
<listitem>
7476
<para>
75-
An expression or value to assign to the column.
77+
An expression to assign to the column. The expression may use the
78+
old values of this and other columns in the table.
7679
</para>
7780
</listitem>
7881
</varlistentry>
@@ -81,7 +84,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
8184
<term><literal>DEFAULT</literal></term>
8285
<listitem>
8386
<para>
84-
This column will be filled with its default value.
87+
Set the column to its default value (which will be NULL if no
88+
specific default expression has been assigned to it).
8589
</para>
8690
</listitem>
8791
</varlistentry>
@@ -91,7 +95,7 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
9195
<listitem>
9296
<para>
9397
A list of table expressions, allowing columns from other tables
94-
to appear in the <literal>WHERE</> condition.
98+
to appear in the <literal>WHERE</> condition and the update expressions.
9599
</para>
96100
</listitem>
97101
</varlistentry>
@@ -100,9 +104,9 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
100104
<term><replaceable class="PARAMETER">condition</replaceable></term>
101105
<listitem>
102106
<para>
103-
A valueexpression that returns a value of type
104-
<type>boolean</type> that determines therows whichare to be
105-
updated.
107+
Anexpression that returns a value of type <type>boolean</type>.
108+
Onlyrowsforwhichthis expression returns <literal>true</>
109+
will beupdated.
106110
</para>
107111
</listitem>
108112
</varlistentry>
@@ -135,9 +139,20 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
135139
column <structfield>kind</> of the table <literal>films</literal>:
136140

137141
<programlisting>
138-
UPDATEfilme SET kind = 'Dramatic' WHERE kind = 'Drama';
142+
UPDATEfilms SET kind = 'Dramatic' WHERE kind = 'Drama';
139143
</programlisting>
140144
</para>
145+
146+
<para>
147+
Adjust temperature entries and reset precipitation to its default
148+
value in one row of the table <literal>weather</literal>:
149+
150+
<programlisting>
151+
UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT
152+
WHERE city = 'San Francisco' AND date = '2003-07-03';
153+
</programlisting>
154+
</para>
155+
141156
</refsect1>
142157

143158
<refsect1>

‎src/backend/nodes/copyfuncs.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.258 2003/06/29 00:33:43 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.259 2003/07/03 16:32:20 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1041,6 +1041,20 @@ _copyCoerceToDomainValue(CoerceToDomainValue *from)
10411041
returnnewnode;
10421042
}
10431043

1044+
/*
1045+
* _copySetToDefault
1046+
*/
1047+
staticSetToDefault*
1048+
_copySetToDefault(SetToDefault*from)
1049+
{
1050+
SetToDefault*newnode=makeNode(SetToDefault);
1051+
1052+
COPY_SCALAR_FIELD(typeId);
1053+
COPY_SCALAR_FIELD(typeMod);
1054+
1055+
returnnewnode;
1056+
}
1057+
10441058
/*
10451059
* _copyTargetEntry
10461060
*/
@@ -1669,14 +1683,6 @@ _copyFuncWithArgs(FuncWithArgs *from)
16691683
returnnewnode;
16701684
}
16711685

1672-
staticSetToDefault*
1673-
_copySetToDefault(SetToDefault*from)
1674-
{
1675-
SetToDefault*newnode=makeNode(SetToDefault);
1676-
1677-
returnnewnode;
1678-
}
1679-
16801686
staticDeclareCursorStmt*
16811687
_copyDeclareCursorStmt(DeclareCursorStmt*from)
16821688
{
@@ -2607,6 +2613,9 @@ copyObject(void *from)
26072613
caseT_CoerceToDomainValue:
26082614
retval=_copyCoerceToDomainValue(from);
26092615
break;
2616+
caseT_SetToDefault:
2617+
retval=_copySetToDefault(from);
2618+
break;
26102619
caseT_TargetEntry:
26112620
retval=_copyTargetEntry(from);
26122621
break;
@@ -2955,9 +2964,6 @@ copyObject(void *from)
29552964
caseT_FuncWithArgs:
29562965
retval=_copyFuncWithArgs(from);
29572966
break;
2958-
caseT_SetToDefault:
2959-
retval=_copySetToDefault(from);
2960-
break;
29612967

29622968
default:
29632969
elog(ERROR,"copyObject: don't know how to copy node type %d",

‎src/backend/nodes/equalfuncs.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.201 2003/06/29 00:33:43 tgl Exp $
21+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.202 2003/07/03 16:32:32 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -485,6 +485,15 @@ _equalCoerceToDomainValue(CoerceToDomainValue *a, CoerceToDomainValue *b)
485485
return true;
486486
}
487487

488+
staticbool
489+
_equalSetToDefault(SetToDefault*a,SetToDefault*b)
490+
{
491+
COMPARE_SCALAR_FIELD(typeId);
492+
COMPARE_SCALAR_FIELD(typeMod);
493+
494+
return true;
495+
}
496+
488497
staticbool
489498
_equalTargetEntry(TargetEntry*a,TargetEntry*b)
490499
{
@@ -740,12 +749,6 @@ _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
740749
return true;
741750
}
742751

743-
staticbool
744-
_equalSetToDefault(SetToDefault*a,SetToDefault*b)
745-
{
746-
return true;
747-
}
748-
749752
staticbool
750753
_equalDeclareCursorStmt(DeclareCursorStmt*a,DeclareCursorStmt*b)
751754
{
@@ -1727,6 +1730,9 @@ equal(void *a, void *b)
17271730
caseT_CoerceToDomainValue:
17281731
retval=_equalCoerceToDomainValue(a,b);
17291732
break;
1733+
caseT_SetToDefault:
1734+
retval=_equalSetToDefault(a,b);
1735+
break;
17301736
caseT_TargetEntry:
17311737
retval=_equalTargetEntry(a,b);
17321738
break;
@@ -2073,9 +2079,6 @@ equal(void *a, void *b)
20732079
caseT_FuncWithArgs:
20742080
retval=_equalFuncWithArgs(a,b);
20752081
break;
2076-
caseT_SetToDefault:
2077-
retval=_equalSetToDefault(a,b);
2078-
break;
20792082

20802083
default:
20812084
elog(WARNING,"equal: don't know whether nodes of type %d are equal",

‎src/backend/nodes/outfuncs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.211 2003/06/29 00:33:43 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.212 2003/07/03 16:32:38 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -849,6 +849,15 @@ _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
849849
WRITE_INT_FIELD(typeMod);
850850
}
851851

852+
staticvoid
853+
_outSetToDefault(StringInfostr,SetToDefault*node)
854+
{
855+
WRITE_NODE_TYPE("SETTODEFAULT");
856+
857+
WRITE_OID_FIELD(typeId);
858+
WRITE_INT_FIELD(typeMod);
859+
}
860+
852861
staticvoid
853862
_outTargetEntry(StringInfostr,TargetEntry*node)
854863
{
@@ -1685,6 +1694,9 @@ _outNode(StringInfo str, void *obj)
16851694
caseT_CoerceToDomainValue:
16861695
_outCoerceToDomainValue(str,obj);
16871696
break;
1697+
caseT_SetToDefault:
1698+
_outSetToDefault(str,obj);
1699+
break;
16881700
caseT_TargetEntry:
16891701
_outTargetEntry(str,obj);
16901702
break;

‎src/backend/nodes/readfuncs.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.157 2003/06/29 00:33:43 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.158 2003/07/03 16:32:39 tgl Exp $
1212
*
1313
* NOTES
1414
* Path and Plan nodes do not have any readfuncs support, because we
@@ -760,6 +760,20 @@ _readCoerceToDomainValue(void)
760760
READ_DONE();
761761
}
762762

763+
/*
764+
* _readSetToDefault
765+
*/
766+
staticSetToDefault*
767+
_readSetToDefault(void)
768+
{
769+
READ_LOCALS(SetToDefault);
770+
771+
READ_OID_FIELD(typeId);
772+
READ_INT_FIELD(typeMod);
773+
774+
READ_DONE();
775+
}
776+
763777
/*
764778
* _readTargetEntry
765779
*/
@@ -1005,6 +1019,8 @@ parseNodeString(void)
10051019
return_value=_readCoerceToDomain();
10061020
elseif (MATCH("COERCETODOMAINVALUE",19))
10071021
return_value=_readCoerceToDomainValue();
1022+
elseif (MATCH("SETTODEFAULT",12))
1023+
return_value=_readSetToDefault();
10081024
elseif (MATCH("TARGETENTRY",11))
10091025
return_value=_readTargetEntry();
10101026
elseif (MATCH("RANGETBLREF",11))

‎src/backend/optimizer/util/clauses.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.144 2003/07/01 19:07:02 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.145 2003/07/03 16:33:07 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -2157,6 +2157,7 @@ expression_tree_walker(Node *node,
21572157
caseT_Const:
21582158
caseT_Param:
21592159
caseT_CoerceToDomainValue:
2160+
caseT_SetToDefault:
21602161
caseT_RangeTblRef:
21612162
/* primitive node types with no subnodes */
21622163
break;
@@ -2514,6 +2515,7 @@ expression_tree_mutator(Node *node,
25142515
caseT_Const:
25152516
caseT_Param:
25162517
caseT_CoerceToDomainValue:
2518+
caseT_SetToDefault:
25172519
caseT_RangeTblRef:
25182520
/* primitive node types with no subnodes */
25192521
return (Node*)copyObject(node);

‎src/backend/parser/gram.y

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.424 2003/07/01 00:04:31 petere Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.425 2003/07/03 16:33:37 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -6999,15 +6999,14 @@ update_target_el:
69996999
$$ =makeNode(ResTarget);
70007000
$$->name = $1;
70017001
$$->indirection = $2;
7002-
$$->val = (Node *)$4;
7002+
$$->val = (Node *)$4;
70037003
}
70047004
| ColId opt_indirection'=' DEFAULT
70057005
{
7006-
SetToDefault *def =makeNode(SetToDefault);
70077006
$$ =makeNode(ResTarget);
70087007
$$->name = $1;
7009-
$$->indirection =NULL;
7010-
$$->val = (Node *)def;
7008+
$$->indirection =$2;
7009+
$$->val = (Node *)makeNode(SetToDefault);
70117010
}
70127011

70137012
;
@@ -7021,11 +7020,10 @@ insert_target_el:
70217020
target_el{ $$ = $1; }
70227021
| DEFAULT
70237022
{
7024-
SetToDefault *def =makeNode(SetToDefault);
70257023
$$ =makeNode(ResTarget);
70267024
$$->name =NULL;
7027-
$$->indirection =NULL;
7028-
$$->val = (Node *)def;
7025+
$$->indirection =NIL;
7026+
$$->val = (Node *)makeNode(SetToDefault);
70297027
}
70307028
;
70317029

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp