1
1
<!--
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 $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -28,7 +28,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
28
28
<para>
29
29
<command>UPDATE</command> changes the values of the specified
30
30
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.
32
33
</para>
33
34
34
35
<para>
@@ -41,8 +42,9 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
41
42
<para>
42
43
You must have the <literal>UPDATE</literal> privilege on the table
43
44
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>.
46
48
</para>
47
49
</refsect1>
48
50
@@ -72,7 +74,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
72
74
<term><replaceable class="PARAMETER">expression</replaceable></term>
73
75
<listitem>
74
76
<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.
76
79
</para>
77
80
</listitem>
78
81
</varlistentry>
@@ -81,7 +84,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
81
84
<term><literal>DEFAULT</literal></term>
82
85
<listitem>
83
86
<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).
85
89
</para>
86
90
</listitem>
87
91
</varlistentry>
@@ -91,7 +95,7 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
91
95
<listitem>
92
96
<para>
93
97
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 .
95
99
</para>
96
100
</listitem>
97
101
</varlistentry>
@@ -100,9 +104,9 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
100
104
<term><replaceable class="PARAMETER">condition</replaceable></term>
101
105
<listitem>
102
106
<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.
106
110
</para>
107
111
</listitem>
108
112
</varlistentry>
@@ -135,9 +139,20 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
135
139
column <structfield>kind</> of the table <literal>films</literal>:
136
140
137
141
<programlisting>
138
- UPDATE filme SET kind = 'Dramatic' WHERE kind = 'Drama';
142
+ UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';
139
143
</programlisting>
140
144
</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
+
141
156
</refsect1>
142
157
143
158
<refsect1>
0 commit comments