Imported upstream version 1.5
[manpages-zh.git] / raw / man7 / update.7
blob75b9f20143710c4542777771a8608a5f03166cc4
1 .\\" auto-generated by docbook2man-spec $Revision: 1.1 $
2 .TH "UPDATE" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands"
3 .SH NAME
4 UPDATE \- update rows of a table
6 .SH SYNOPSIS
7 .sp
8 .nf
9 UPDATE [ ONLY ] \fItable\fR SET \fIcolumn\fR = { \fIexpression\fR | DEFAULT } [, ...]
10     [ FROM \fIfromlist\fR ]
11     [ WHERE \fIcondition\fR ]
12 .sp
13 .fi
14 .SH "DESCRIPTION"
15 .PP
16 \fBUPDATE\fR changes the values of the specified
17 columns in all rows that satisfy the condition. Only the columns to
18 be modified need be mentioned in the statement; columns not explicitly
19 SET retain their previous values.
20 .PP
21 By default, \fBUPDATE\fR will update rows in the
22 specified table and all its subtables. If you wish to only update
23 the specific table mentioned, you must use the ONLY
24 clause.
25 .PP
26 You must have the UPDATE privilege on the table
27 to update it, as well as the SELECT
28 privilege to any table whose values are read in the
29 \fIexpression\fRs or
30 \fIcondition\fR.
31 .SH "PARAMETERS"
32 .TP
33 \fB\fItable\fB\fR
34 The name (optionally schema-qualified) of the table to update.
35 .TP
36 \fB\fIcolumn\fB\fR
37 The name of a column in \fItable\fR.
38 .TP
39 \fB\fIexpression\fB\fR
40 An expression to assign to the column. The expression may use the
41 old values of this and other columns in the table.
42 .TP
43 \fBDEFAULT\fR
44 Set the column to its default value (which will be NULL if no
45 specific default expression has been assigned to it).
46 .TP
47 \fB\fIfromlist\fB\fR
48 A list of table expressions, allowing columns from other tables
49 to appear in the WHERE condition and the update expressions.
50 .TP
51 \fB\fIcondition\fB\fR
52 An expression that returns a value of type \fBboolean\fR.
53 Only rows for which this expression returns true
54 will be updated.
55 .SH "OUTPUTS"
56 .PP
57 On successful completion, an \fBUPDATE\fR command returns a command
58 tag of the form
59 .sp
60 .nf
61 UPDATE \fIcount\fR
62 .sp
63 .fi
64 The \fIcount\fR is the number
65 of rows updated. If \fIcount\fR is
66 0, no rows matched the \fIcondition\fR (this is not considered
67 an error).
68 .SH "EXAMPLES"
69 .PP
70 Change the word Drama to Dramatic in the
71 column \fBkind\fR of the table films:
72 .sp
73 .nf
74 UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';
75 .sp
76 .fi
77 .PP
78 Adjust temperature entries and reset precipitation to its default
79 value in one row of the table weather:
80 .sp
81 .nf
82 UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT
83   WHERE city = 'San Francisco' AND date = '2003-07-03';
84 .sp
85 .fi
86 .SH "COMPATIBILITY"
87 .PP
88 This command conforms to the SQL standard. The
89 FROM clause is a
90 PostgreSQL extension.