2 $Header: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v 1.12 2000/10/05 19:57:23 momjian Exp $
6 <refentry id="SQL-UPDATE">
8 <refentrytitle id="SQL-UPDATE-TITLE">
11 <refmiscinfo>SQL - Language Statements</refmiscinfo>
18 Replaces values of columns in a table
23 <date>1999-07-20</date>
26 UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replaceable class="PARAMETER">col</replaceable> = <replaceable class="PARAMETER">expression</replaceable> [, ...]
27 [ FROM <replaceable class="PARAMETER">fromlist</replaceable> ]
28 [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
31 <refsect2 id="R2-SQL-UPDATE-1">
33 <date>1998-09-24</date>
42 <term><replaceable class="PARAMETER">table</replaceable></term>
45 The name of an existing table.
50 <term><replaceable class="PARAMETER">column</replaceable></term>
53 The name of a column in <replaceable class="PARAMETER">table</replaceable>.
58 <term><replaceable class="PARAMETER">expression</replaceable></term>
61 A valid expression or value to assign to column.
66 <term><replaceable class="PARAMETER">fromlist</replaceable></term>
69 A <productname>Postgres</productname>
70 non-standard extension to allow columns
71 from other tables to appear in the WHERE condition.
76 <term><replaceable class="PARAMETER">condition</replaceable></term>
79 Refer to the SELECT statement for a further description
88 <refsect2 id="R2-SQL-UPDATE-2">
90 <date>1998-09-24</date>
99 <term><computeroutput>
100 UPDATE <replaceable class="parameter">#</replaceable>
101 </computeroutput></term>
104 Message returned if successful.
105 The <replaceable class="parameter">#</replaceable>
106 means the number of rows updated.
107 If <replaceable class="parameter">#</replaceable>
108 is 0 no rows are updated.
117 <refsect1 id="R1-SQL-UPDATE-1">
119 <date>1998-09-24</date>
125 <command>UPDATE</command> changes the values of the columns specified for
126 all rows which satisfy condition. Only the columns
127 to be modified need appear as columns in the statement.
131 Array references use the same syntax found in
132 <xref linkend="sql-select-title" endterm="sql-select-title">.
133 That is, either single array elements, a range of array
134 elements or the entire array may be replaced with a single
139 You must have write access to the table in order to modify
140 it, as well as read access to any table whose values are
141 mentioned in the WHERE condition.
145 By default UPDATE will update tuples in the table specified
146 and all its sub-classes. If you wish to only update the
147 specific table mentioned, you should use the ONLY clause.
151 <refsect1 id="R1-SQL-UPDATE-2">
157 Change word "Drama" with "Dramatic" on column kind:
161 SET kind = 'Dramatic'
162 WHERE kind = 'Drama';
165 WHERE kind = 'Dramatic' OR kind = 'Drama';
167 code | title | did | date_prod | kind | len
168 -------+---------------+-----+------------+----------+-------
169 BL101 | The Third Man | 101 | 1949-12-23 | Dramatic | 01:44
170 P_302 | Becket | 103 | 1964-02-03 | Dramatic | 02:28
171 M_401 | War and Peace | 104 | 1967-02-12 | Dramatic | 05:57
172 T_601 | Yojimbo | 106 | 1961-06-16 | Dramatic | 01:50
173 DA101 | Das Boot | 110 | 1981-11-11 | Dramatic | 02:29
178 <refsect1 id="R1-SQL-UPDATE-3">
183 <refsect2 id="R2-SQL-UPDATE-4">
185 <date>1998-09-24</date>
191 <acronym>SQL92</acronym> defines a different syntax for
192 the positioned UPDATE statement:
195 UPDATE <replaceable>table</replaceable> SET <replaceable>column</replaceable> = <replaceable>expression</replaceable> [, ...]
196 WHERE CURRENT OF <replaceable class="parameter">cursor</replaceable>
199 where <replaceable class="parameter">cursor</replaceable>
200 identifies an open cursor.
206 <!-- Keep this comment at the end of the file
211 sgml-minimize-attributes:nil
212 sgml-always-quote-attributes:t
215 sgml-parent-document:nil
216 sgml-default-dtd-file:"../reference.ced"
217 sgml-exposed-tags:nil
218 sgml-local-catalogs:"/usr/lib/sgml/catalog"
219 sgml-local-ecat-files:nil