Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 455891b

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 parent 7b1885b commit 455891b

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, either a declared default value
36+
using a default value, either its 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 filled with their 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 value expression that returns a value of type
104-
<type>boolean</type> that determines the rows which are to be
105-
updated.
107+
An expression that returns a value of type <type>boolean</type>.
108+
Only rows for which this expression returns <literal>true</>
109+
will be updated.
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-
UPDATE filme SET kind = 'Dramatic' WHERE kind = 'Drama';
142+
UPDATE films 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
return newnode;
10421042
}
10431043

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

1672-
static SetToDefault *
1673-
_copySetToDefault(SetToDefault *from)
1674-
{
1675-
SetToDefault *newnode = makeNode(SetToDefault);
1676-
1677-
return newnode;
1678-
}
1679-
16801686
static DeclareCursorStmt *
16811687
_copyDeclareCursorStmt(DeclareCursorStmt *from)
16821688
{
@@ -2607,6 +2613,9 @@ copyObject(void *from)
26072613
case T_CoerceToDomainValue:
26082614
retval = _copyCoerceToDomainValue(from);
26092615
break;
2616+
case T_SetToDefault:
2617+
retval = _copySetToDefault(from);
2618+
break;
26102619
case T_TargetEntry:
26112620
retval = _copyTargetEntry(from);
26122621
break;
@@ -2955,9 +2964,6 @@ copyObject(void *from)
29552964
case T_FuncWithArgs:
29562965
retval = _copyFuncWithArgs(from);
29572966
break;
2958-
case T_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+
static bool
489+
_equalSetToDefault(SetToDefault *a, SetToDefault *b)
490+
{
491+
COMPARE_SCALAR_FIELD(typeId);
492+
COMPARE_SCALAR_FIELD(typeMod);
493+
494+
return true;
495+
}
496+
488497
static bool
489498
_equalTargetEntry(TargetEntry *a, TargetEntry *b)
490499
{
@@ -740,12 +749,6 @@ _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
740749
return true;
741750
}
742751

743-
static bool
744-
_equalSetToDefault(SetToDefault *a, SetToDefault *b)
745-
{
746-
return true;
747-
}
748-
749752
static bool
750753
_equalDeclareCursorStmt(DeclareCursorStmt *a, DeclareCursorStmt *b)
751754
{
@@ -1727,6 +1730,9 @@ equal(void *a, void *b)
17271730
case T_CoerceToDomainValue:
17281731
retval = _equalCoerceToDomainValue(a, b);
17291732
break;
1733+
case T_SetToDefault:
1734+
retval = _equalSetToDefault(a, b);
1735+
break;
17301736
case T_TargetEntry:
17311737
retval = _equalTargetEntry(a, b);
17321738
break;
@@ -2073,9 +2079,6 @@ equal(void *a, void *b)
20732079
case T_FuncWithArgs:
20742080
retval = _equalFuncWithArgs(a, b);
20752081
break;
2076-
case T_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+
static void
853+
_outSetToDefault(StringInfo str, SetToDefault *node)
854+
{
855+
WRITE_NODE_TYPE("SETTODEFAULT");
856+
857+
WRITE_OID_FIELD(typeId);
858+
WRITE_INT_FIELD(typeMod);
859+
}
860+
852861
static void
853862
_outTargetEntry(StringInfo str, TargetEntry *node)
854863
{
@@ -1685,6 +1694,9 @@ _outNode(StringInfo str, void *obj)
16851694
case T_CoerceToDomainValue:
16861695
_outCoerceToDomainValue(str, obj);
16871696
break;
1697+
case T_SetToDefault:
1698+
_outSetToDefault(str, obj);
1699+
break;
16881700
case T_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+
static SetToDefault *
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
else if (MATCH("COERCETODOMAINVALUE", 19))
10071021
return_value = _readCoerceToDomainValue();
1022+
else if (MATCH("SETTODEFAULT", 12))
1023+
return_value = _readSetToDefault();
10081024
else if (MATCH("TARGETENTRY", 11))
10091025
return_value = _readTargetEntry();
10101026
else if (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
* AUTHOR DATE MAJOR EVENT
@@ -2157,6 +2157,7 @@ expression_tree_walker(Node *node,
21572157
case T_Const:
21582158
case T_Param:
21592159
case T_CoerceToDomainValue:
2160+
case T_SetToDefault:
21602161
case T_RangeTblRef:
21612162
/* primitive node types with no subnodes */
21622163
break;
@@ -2514,6 +2515,7 @@ expression_tree_mutator(Node *node,
25142515
case T_Const:
25152516
case T_Param:
25162517
case T_CoerceToDomainValue:
2518+
case T_SetToDefault:
25172519
case T_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
* AUTHOR DATE MAJOR 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)