postgresql/doc/src/sgml/ref/update.sgml

160 lines
4.2 KiB
Plaintext
Raw Normal View History

<!--
2003-04-27 01:56:51 +02:00
$Header: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v 1.21 2003/04/26 23:56:51 petere Exp $
PostgreSQL documentation
-->
<refentry id="SQL-UPDATE">
<refmeta>
<refentrytitle id="SQL-UPDATE-TITLE">UPDATE</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
2003-04-27 01:56:51 +02:00
<refnamediv>
2003-04-27 01:56:51 +02:00
<refname>UPDATE</refname>
<refpurpose>update rows of a table</refpurpose>
</refnamediv>
2003-04-27 01:56:51 +02:00
<refsynopsisdiv>
2003-04-27 01:56:51 +02:00
<synopsis>
UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replaceable class="PARAMETER">column</replaceable> = <replaceable class="PARAMETER">expression</replaceable> [, ...]
[ FROM <replaceable class="PARAMETER">fromlist</replaceable> ]
[ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
2003-04-27 01:56:51 +02:00
</synopsis>
</refsynopsisdiv>
2003-04-27 01:56:51 +02:00
<refsect1>
<title>Description</title>
<para>
2003-04-27 01:56:51 +02:00
<command>UPDATE</command> changes the values of the specified
columns in all rows that satisfy the condition. Only the columns to
be modified need appear as columns in the statement.
</para>
<para>
2003-04-27 01:56:51 +02:00
By default, <command>UPDATE</command> will update rows in the
specified table and all its subtables. If you wish to only update
the specific table mentioned, you must use the <literal>ONLY</>
clause.
</para>
<para>
2003-04-27 01:56:51 +02:00
You must have the <literal>UPDATE</literal> privilege on the table
to update it, as well as the <literal>SELECT</literal>
privilege to any table whose values are read in the <replaceable
class="parameter">condition</replaceable>.
</para>
</refsect1>
2003-04-27 01:56:51 +02:00
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><replaceable class="PARAMETER">table</replaceable></term>
<listitem>
<para>
The name (optionally schema-qualified) of the table to update.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">column</replaceable></term>
<listitem>
<para>
The name of a column in <replaceable class="PARAMETER">table</replaceable>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">expression</replaceable></term>
<listitem>
<para>
An expression or value to assign to the column.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">fromlist</replaceable></term>
<listitem>
<para>
A list of table expressions, allowing columns from other tables
to appear in the <literal>WHERE</> condition.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">condition</replaceable></term>
<listitem>
<para>
A value expression that returns a value of type
<type>boolean</type> that determines the rows which are to be
updated.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Diagnostics</title>
<variablelist>
<varlistentry>
<term><computeroutput>UPDATE <replaceable class="parameter">count</replaceable></computeroutput></term>
<listitem>
<para>
Message returned if successful. The value <replaceable
class="parameter">count</replaceable> is the number of rows
updated. If <replaceable class="parameter">count</replaceable>
is 0, no rows were updated.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Examples</title>
<para>
2003-04-27 01:56:51 +02:00
Change the word <literal>Drama</> to <literal>Dramatic</> in the
column <structfield>kind</> of the table <literal>films</literal>:
<programlisting>
2003-04-27 01:56:51 +02:00
UPDATE filme SET kind = 'Dramatic' WHERE kind = 'Drama';
</programlisting>
</para>
</refsect1>
2003-04-27 01:56:51 +02:00
<refsect1>
<title>Compatibility</title>
<para>
This command conforms to the SQL standard. The
<literal>FROM</literal> clause is a PostgreSQL extension.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->