2 $Header: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v 1.9 2000/04/11 05:39:15 thomas 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 <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 equal 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 <refsect1 id="R1-SQL-UPDATE-2">
151 Change word "Drama" with "Dramatic" on column kind:
154 UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';
155 SELECT * FROM films WHERE kind = 'Dramatic' OR kind = 'Drama';
157 code | title | did | date_prod | kind | len
158 -------+---------------+-----+------------+----------+-------
159 BL101 | The Third Man | 101 | 1949-12-23 | Dramatic | 01:44
160 P_302 | Becket | 103 | 1964-02-03 | Dramatic | 02:28
161 M_401 | War and Peace | 104 | 1967-02-12 | Dramatic | 05:57
162 T_601 | Yojimbo | 106 | 1961-06-16 | Dramatic | 01:50
163 DA101 | Das Boot | 110 | 1981-11-11 | Dramatic | 02:29
168 <refsect1 id="R1-SQL-UPDATE-3">
173 <refsect2 id="R2-SQL-UPDATE-4">
175 <date>1998-09-24</date>
181 <acronym>SQL92</acronym> defines a different syntax for
182 the positioned UPDATE statement:
185 UPDATE <replaceable>table</replaceable> SET <replaceable>column</replaceable> = <replaceable>expression</replaceable> [, ...]
186 WHERE CURRENT OF <replaceable class="parameter">cursor</replaceable>
189 where <replaceable class="parameter">cursor</replaceable>
190 identifies an open cursor.
196 <!-- Keep this comment at the end of the file
201 sgml-minimize-attributes:nil
202 sgml-always-quote-attributes:t
205 sgml-parent-document:nil
206 sgml-default-dtd-file:"../reference.ced"
207 sgml-exposed-tags:nil
208 sgml-local-catalogs:"/usr/lib/sgml/catalog"
209 sgml-local-ecat-files:nil