~ubuntu-branches/ubuntu/precise/postgresql-9.1/precise-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/html/sql-update.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>UPDATE</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REV="MADE"
 
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
 
11
REL="HOME"
 
12
TITLE="PostgreSQL 9.1beta1 Documentation"
 
13
HREF="index.html"><LINK
 
14
REL="UP"
 
15
TITLE="SQL Commands"
 
16
HREF="sql-commands.html"><LINK
 
17
REL="PREVIOUS"
 
18
TITLE="UNLISTEN"
 
19
HREF="sql-unlisten.html"><LINK
 
20
REL="NEXT"
 
21
TITLE="VACUUM"
 
22
HREF="sql-vacuum.html"><LINK
 
23
REL="STYLESHEET"
 
24
TYPE="text/css"
 
25
HREF="stylesheet.css"><META
 
26
HTTP-EQUIV="Content-Type"
 
27
CONTENT="text/html; charset=ISO-8859-1"><META
 
28
NAME="creation"
 
29
CONTENT="2011-04-27T21:20:33"></HEAD
 
30
><BODY
 
31
CLASS="REFENTRY"
 
32
><DIV
 
33
CLASS="NAVHEADER"
 
34
><TABLE
 
35
SUMMARY="Header navigation table"
 
36
WIDTH="100%"
 
37
BORDER="0"
 
38
CELLPADDING="0"
 
39
CELLSPACING="0"
 
40
><TR
 
41
><TH
 
42
COLSPAN="5"
 
43
ALIGN="center"
 
44
VALIGN="bottom"
 
45
><A
 
46
HREF="index.html"
 
47
>PostgreSQL 9.1beta1 Documentation</A
 
48
></TH
 
49
></TR
 
50
><TR
 
51
><TD
 
52
WIDTH="10%"
 
53
ALIGN="left"
 
54
VALIGN="top"
 
55
><A
 
56
TITLE="UNLISTEN"
 
57
HREF="sql-unlisten.html"
 
58
ACCESSKEY="P"
 
59
>Prev</A
 
60
></TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="left"
 
64
VALIGN="top"
 
65
><A
 
66
TITLE="UNLISTEN"
 
67
HREF="sql-unlisten.html"
 
68
>Fast Backward</A
 
69
></TD
 
70
><TD
 
71
WIDTH="60%"
 
72
ALIGN="center"
 
73
VALIGN="bottom"
 
74
></TD
 
75
><TD
 
76
WIDTH="10%"
 
77
ALIGN="right"
 
78
VALIGN="top"
 
79
><A
 
80
TITLE="VACUUM"
 
81
HREF="sql-vacuum.html"
 
82
>Fast Forward</A
 
83
></TD
 
84
><TD
 
85
WIDTH="10%"
 
86
ALIGN="right"
 
87
VALIGN="top"
 
88
><A
 
89
TITLE="VACUUM"
 
90
HREF="sql-vacuum.html"
 
91
ACCESSKEY="N"
 
92
>Next</A
 
93
></TD
 
94
></TR
 
95
></TABLE
 
96
><HR
 
97
ALIGN="LEFT"
 
98
WIDTH="100%"></DIV
 
99
><H1
 
100
><A
 
101
NAME="SQL-UPDATE"
 
102
></A
 
103
>UPDATE</H1
 
104
><DIV
 
105
CLASS="REFNAMEDIV"
 
106
><A
 
107
NAME="AEN75966"
 
108
></A
 
109
><H2
 
110
>Name</H2
 
111
>UPDATE&nbsp;--&nbsp;update rows of a table</DIV
 
112
><DIV
 
113
CLASS="REFSYNOPSISDIV"
 
114
><A
 
115
NAME="AEN75971"
 
116
></A
 
117
><H2
 
118
>Synopsis</H2
 
119
><PRE
 
120
CLASS="SYNOPSIS"
 
121
>[ WITH [ RECURSIVE ] <TT
 
122
CLASS="REPLACEABLE"
 
123
><I
 
124
>with_query</I
 
125
></TT
 
126
> [, ...] ]
 
127
UPDATE [ ONLY ] <TT
 
128
CLASS="REPLACEABLE"
 
129
><I
 
130
>table</I
 
131
></TT
 
132
> [ [ AS ] <TT
 
133
CLASS="REPLACEABLE"
 
134
><I
 
135
>alias</I
 
136
></TT
 
137
> ]
 
138
    SET { <TT
 
139
CLASS="REPLACEABLE"
 
140
><I
 
141
>column</I
 
142
></TT
 
143
> = { <TT
 
144
CLASS="REPLACEABLE"
 
145
><I
 
146
>expression</I
 
147
></TT
 
148
> | DEFAULT } |
 
149
          ( <TT
 
150
CLASS="REPLACEABLE"
 
151
><I
 
152
>column</I
 
153
></TT
 
154
> [, ...] ) = ( { <TT
 
155
CLASS="REPLACEABLE"
 
156
><I
 
157
>expression</I
 
158
></TT
 
159
> | DEFAULT } [, ...] ) } [, ...]
 
160
    [ FROM <TT
 
161
CLASS="REPLACEABLE"
 
162
><I
 
163
>from_list</I
 
164
></TT
 
165
> ]
 
166
    [ WHERE <TT
 
167
CLASS="REPLACEABLE"
 
168
><I
 
169
>condition</I
 
170
></TT
 
171
> | WHERE CURRENT OF <TT
 
172
CLASS="REPLACEABLE"
 
173
><I
 
174
>cursor_name</I
 
175
></TT
 
176
> ]
 
177
    [ RETURNING * | <TT
 
178
CLASS="REPLACEABLE"
 
179
><I
 
180
>output_expression</I
 
181
></TT
 
182
> [ [ AS ] <TT
 
183
CLASS="REPLACEABLE"
 
184
><I
 
185
>output_name</I
 
186
></TT
 
187
> ] [, ...] ]</PRE
 
188
></DIV
 
189
><DIV
 
190
CLASS="REFSECT1"
 
191
><A
 
192
NAME="AEN75985"
 
193
></A
 
194
><H2
 
195
>Description</H2
 
196
><P
 
197
>   <TT
 
198
CLASS="COMMAND"
 
199
>UPDATE</TT
 
200
> changes the values of the specified
 
201
   columns in all rows that satisfy the condition. Only the columns to
 
202
   be modified need be mentioned in the <TT
 
203
CLASS="LITERAL"
 
204
>SET</TT
 
205
> clause;
 
206
   columns not explicitly modified retain their previous values.
 
207
  </P
 
208
><P
 
209
>   By default, <TT
 
210
CLASS="COMMAND"
 
211
>UPDATE</TT
 
212
> will update rows in the
 
213
   specified table and all its subtables. If you wish to only update
 
214
   the specific table mentioned, you must use the <TT
 
215
CLASS="LITERAL"
 
216
>ONLY</TT
 
217
>
 
218
   clause.
 
219
  </P
 
220
><P
 
221
>   There are two ways to modify a table using information contained in
 
222
   other tables in the database: using sub-selects, or specifying
 
223
   additional tables in the <TT
 
224
CLASS="LITERAL"
 
225
>FROM</TT
 
226
> clause. Which
 
227
   technique is more appropriate depends on the specific
 
228
   circumstances.
 
229
  </P
 
230
><P
 
231
>   The optional <TT
 
232
CLASS="LITERAL"
 
233
>RETURNING</TT
 
234
> clause causes <TT
 
235
CLASS="COMMAND"
 
236
>UPDATE</TT
 
237
>
 
238
   to compute and return value(s) based on each row actually updated.
 
239
   Any expression using the table's columns, and/or columns of other
 
240
   tables mentioned in <TT
 
241
CLASS="LITERAL"
 
242
>FROM</TT
 
243
>, can be computed.
 
244
   The new (post-update) values of the table's columns are used.
 
245
   The syntax of the <TT
 
246
CLASS="LITERAL"
 
247
>RETURNING</TT
 
248
> list is identical to that of the
 
249
   output list of <TT
 
250
CLASS="COMMAND"
 
251
>SELECT</TT
 
252
>.
 
253
  </P
 
254
><P
 
255
>   You must have the <TT
 
256
CLASS="LITERAL"
 
257
>UPDATE</TT
 
258
> privilege on the table,
 
259
   or at least on the column(s) that are listed to be updated.
 
260
   You must also have the <TT
 
261
CLASS="LITERAL"
 
262
>SELECT</TT
 
263
>
 
264
   privilege on any column whose values are read in the
 
265
   <TT
 
266
CLASS="REPLACEABLE"
 
267
><I
 
268
>expressions</I
 
269
></TT
 
270
> or
 
271
   <TT
 
272
CLASS="REPLACEABLE"
 
273
><I
 
274
>condition</I
 
275
></TT
 
276
>.
 
277
  </P
 
278
></DIV
 
279
><DIV
 
280
CLASS="REFSECT1"
 
281
><A
 
282
NAME="AEN76006"
 
283
></A
 
284
><H2
 
285
>Parameters</H2
 
286
><P
 
287
></P
 
288
><DIV
 
289
CLASS="VARIABLELIST"
 
290
><DL
 
291
><DT
 
292
><TT
 
293
CLASS="REPLACEABLE"
 
294
><I
 
295
>with_query</I
 
296
></TT
 
297
></DT
 
298
><DD
 
299
><P
 
300
>      The <TT
 
301
CLASS="LITERAL"
 
302
>WITH</TT
 
303
> clause allows you to specify one or more
 
304
      subqueries that can be referenced by name in the <TT
 
305
CLASS="COMMAND"
 
306
>UPDATE</TT
 
307
>
 
308
      query. See <A
 
309
HREF="queries-with.html"
 
310
>Section 7.8</A
 
311
> and <A
 
312
HREF="sql-select.html"
 
313
>SELECT</A
 
314
>
 
315
      for details.
 
316
     </P
 
317
></DD
 
318
><DT
 
319
><TT
 
320
CLASS="REPLACEABLE"
 
321
><I
 
322
>table</I
 
323
></TT
 
324
></DT
 
325
><DD
 
326
><P
 
327
>      The name (optionally schema-qualified) of the table to update.
 
328
     </P
 
329
></DD
 
330
><DT
 
331
><TT
 
332
CLASS="REPLACEABLE"
 
333
><I
 
334
>alias</I
 
335
></TT
 
336
></DT
 
337
><DD
 
338
><P
 
339
>      A substitute name for the target table. When an alias is
 
340
      provided, it completely hides the actual name of the table.  For
 
341
      example, given <TT
 
342
CLASS="LITERAL"
 
343
>UPDATE foo AS f</TT
 
344
>, the remainder of the
 
345
      <TT
 
346
CLASS="COMMAND"
 
347
>UPDATE</TT
 
348
> statement must refer to this table as
 
349
      <TT
 
350
CLASS="LITERAL"
 
351
>f</TT
 
352
> not <TT
 
353
CLASS="LITERAL"
 
354
>foo</TT
 
355
>.
 
356
     </P
 
357
></DD
 
358
><DT
 
359
><TT
 
360
CLASS="REPLACEABLE"
 
361
><I
 
362
>column</I
 
363
></TT
 
364
></DT
 
365
><DD
 
366
><P
 
367
>      The name of a column in <TT
 
368
CLASS="REPLACEABLE"
 
369
><I
 
370
>table</I
 
371
></TT
 
372
>.
 
373
      The column name can be qualified with a subfield name or array
 
374
      subscript, if needed.  Do not include the table's name in the
 
375
      specification of a target column &mdash; for example,
 
376
      <TT
 
377
CLASS="LITERAL"
 
378
>UPDATE tab SET tab.col = 1</TT
 
379
> is invalid.
 
380
     </P
 
381
></DD
 
382
><DT
 
383
><TT
 
384
CLASS="REPLACEABLE"
 
385
><I
 
386
>expression</I
 
387
></TT
 
388
></DT
 
389
><DD
 
390
><P
 
391
>      An expression to assign to the column.  The expression can use the
 
392
      old values of this and other columns in the table.
 
393
     </P
 
394
></DD
 
395
><DT
 
396
><TT
 
397
CLASS="LITERAL"
 
398
>DEFAULT</TT
 
399
></DT
 
400
><DD
 
401
><P
 
402
>      Set the column to its default value (which will be NULL if no
 
403
      specific default expression has been assigned to it).
 
404
     </P
 
405
></DD
 
406
><DT
 
407
><TT
 
408
CLASS="REPLACEABLE"
 
409
><I
 
410
>from_list</I
 
411
></TT
 
412
></DT
 
413
><DD
 
414
><P
 
415
>      A list of table expressions, allowing columns from other tables
 
416
      to appear in the <TT
 
417
CLASS="LITERAL"
 
418
>WHERE</TT
 
419
> condition and the update
 
420
      expressions. This is similar to the list of tables that can be
 
421
      specified in the <A
 
422
HREF="sql-select.html#SQL-FROM"
 
423
><I
 
424
><I
 
425
>FROM</I
 
426
> Clause</I
 
427
></A
 
428
> of a <TT
 
429
CLASS="COMMAND"
 
430
>SELECT</TT
 
431
>
 
432
      statement.  Note that the target table must not appear in the
 
433
      <TT
 
434
CLASS="REPLACEABLE"
 
435
><I
 
436
>from_list</I
 
437
></TT
 
438
>, unless you intend a self-join (in which
 
439
      case it must appear with an alias in the <TT
 
440
CLASS="REPLACEABLE"
 
441
><I
 
442
>from_list</I
 
443
></TT
 
444
>).
 
445
     </P
 
446
></DD
 
447
><DT
 
448
><TT
 
449
CLASS="REPLACEABLE"
 
450
><I
 
451
>condition</I
 
452
></TT
 
453
></DT
 
454
><DD
 
455
><P
 
456
>      An expression that returns a value of type <TT
 
457
CLASS="TYPE"
 
458
>boolean</TT
 
459
>.
 
460
      Only rows for which this expression returns <TT
 
461
CLASS="LITERAL"
 
462
>true</TT
 
463
>
 
464
      will be updated.
 
465
     </P
 
466
></DD
 
467
><DT
 
468
><TT
 
469
CLASS="REPLACEABLE"
 
470
><I
 
471
>cursor_name</I
 
472
></TT
 
473
></DT
 
474
><DD
 
475
><P
 
476
>      The name of the cursor to use in a <TT
 
477
CLASS="LITERAL"
 
478
>WHERE CURRENT OF</TT
 
479
>
 
480
      condition.  The row to be updated is the one most recently fetched
 
481
      from this cursor.  The cursor must be a non-grouping
 
482
      query on the <TT
 
483
CLASS="COMMAND"
 
484
>UPDATE</TT
 
485
>'s target table.
 
486
      Note that <TT
 
487
CLASS="LITERAL"
 
488
>WHERE CURRENT OF</TT
 
489
> cannot be
 
490
      specified together with a Boolean condition.  See
 
491
      <A
 
492
HREF="sql-declare.html"
 
493
>DECLARE</A
 
494
>
 
495
      for more information about using cursors with
 
496
      <TT
 
497
CLASS="LITERAL"
 
498
>WHERE CURRENT OF</TT
 
499
>.
 
500
     </P
 
501
></DD
 
502
><DT
 
503
><TT
 
504
CLASS="REPLACEABLE"
 
505
><I
 
506
>output_expression</I
 
507
></TT
 
508
></DT
 
509
><DD
 
510
><P
 
511
>      An expression to be computed and returned by the <TT
 
512
CLASS="COMMAND"
 
513
>UPDATE</TT
 
514
>
 
515
      command after each row is updated.  The expression can use any
 
516
      column names of the <TT
 
517
CLASS="REPLACEABLE"
 
518
><I
 
519
>table</I
 
520
></TT
 
521
>
 
522
      or table(s) listed in <TT
 
523
CLASS="LITERAL"
 
524
>FROM</TT
 
525
>.
 
526
      Write <TT
 
527
CLASS="LITERAL"
 
528
>*</TT
 
529
> to return all columns.
 
530
     </P
 
531
></DD
 
532
><DT
 
533
><TT
 
534
CLASS="REPLACEABLE"
 
535
><I
 
536
>output_name</I
 
537
></TT
 
538
></DT
 
539
><DD
 
540
><P
 
541
>      A name to use for a returned column.
 
542
     </P
 
543
></DD
 
544
></DL
 
545
></DIV
 
546
></DIV
 
547
><DIV
 
548
CLASS="REFSECT1"
 
549
><A
 
550
NAME="AEN76090"
 
551
></A
 
552
><H2
 
553
>Outputs</H2
 
554
><P
 
555
>   On successful completion, an <TT
 
556
CLASS="COMMAND"
 
557
>UPDATE</TT
 
558
> command returns a command
 
559
   tag of the form
 
560
</P><PRE
 
561
CLASS="SCREEN"
 
562
>UPDATE <TT
 
563
CLASS="REPLACEABLE"
 
564
><I
 
565
>count</I
 
566
></TT
 
567
></PRE
 
568
><P>
 
569
   The <TT
 
570
CLASS="REPLACEABLE"
 
571
><I
 
572
>count</I
 
573
></TT
 
574
> is the number
 
575
   of rows updated.  If <TT
 
576
CLASS="REPLACEABLE"
 
577
><I
 
578
>count</I
 
579
></TT
 
580
> is
 
581
   0, no rows matched the <TT
 
582
CLASS="REPLACEABLE"
 
583
><I
 
584
>condition</I
 
585
></TT
 
586
> (this is not considered
 
587
   an error).
 
588
  </P
 
589
><P
 
590
>   If the <TT
 
591
CLASS="COMMAND"
 
592
>UPDATE</TT
 
593
> command contains a <TT
 
594
CLASS="LITERAL"
 
595
>RETURNING</TT
 
596
>
 
597
   clause, the result will be similar to that of a <TT
 
598
CLASS="COMMAND"
 
599
>SELECT</TT
 
600
>
 
601
   statement containing the columns and values defined in the
 
602
   <TT
 
603
CLASS="LITERAL"
 
604
>RETURNING</TT
 
605
> list, computed over the row(s) updated by the
 
606
   command.
 
607
  </P
 
608
></DIV
 
609
><DIV
 
610
CLASS="REFSECT1"
 
611
><A
 
612
NAME="AEN76104"
 
613
></A
 
614
><H2
 
615
>Notes</H2
 
616
><P
 
617
>   When a <TT
 
618
CLASS="LITERAL"
 
619
>FROM</TT
 
620
> clause is present, what essentially happens
 
621
   is that the target table is joined to the tables mentioned in the
 
622
   <TT
 
623
CLASS="REPLACEABLE"
 
624
><I
 
625
>from_list</I
 
626
></TT
 
627
>, and each output row of the join
 
628
   represents an update operation for the target table.  When using
 
629
   <TT
 
630
CLASS="LITERAL"
 
631
>FROM</TT
 
632
> you should ensure that the join
 
633
   produces at most one output row for each row to be modified.  In
 
634
   other words, a target row shouldn't join to more than one row from
 
635
   the other table(s).  If it does, then only one of the join rows
 
636
   will be used to update the target row, but which one will be used
 
637
   is not readily predictable.
 
638
  </P
 
639
><P
 
640
>   Because of this indeterminacy, referencing other tables only within
 
641
   sub-selects is safer, though often harder to read and slower than
 
642
   using a join.
 
643
  </P
 
644
></DIV
 
645
><DIV
 
646
CLASS="REFSECT1"
 
647
><A
 
648
NAME="AEN76111"
 
649
></A
 
650
><H2
 
651
>Examples</H2
 
652
><P
 
653
>   Change the word <TT
 
654
CLASS="LITERAL"
 
655
>Drama</TT
 
656
> to <TT
 
657
CLASS="LITERAL"
 
658
>Dramatic</TT
 
659
> in the
 
660
   column <TT
 
661
CLASS="STRUCTFIELD"
 
662
>kind</TT
 
663
> of the table <TT
 
664
CLASS="STRUCTNAME"
 
665
>films</TT
 
666
>:
 
667
 
 
668
</P><PRE
 
669
CLASS="PROGRAMLISTING"
 
670
>UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';</PRE
 
671
><P>
 
672
  </P
 
673
><P
 
674
>   Adjust temperature entries and reset precipitation to its default
 
675
   value in one row of the table <TT
 
676
CLASS="STRUCTNAME"
 
677
>weather</TT
 
678
>:
 
679
 
 
680
</P><PRE
 
681
CLASS="PROGRAMLISTING"
 
682
>UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT
 
683
  WHERE city = 'San Francisco' AND date = '2003-07-03';</PRE
 
684
><P>
 
685
  </P
 
686
><P
 
687
>   Perform the same operation and return the updated entries:
 
688
 
 
689
</P><PRE
 
690
CLASS="PROGRAMLISTING"
 
691
>UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT
 
692
  WHERE city = 'San Francisco' AND date = '2003-07-03'
 
693
  RETURNING temp_lo, temp_hi, prcp;</PRE
 
694
><P>
 
695
  </P
 
696
><P
 
697
>   Use the alternative column-list syntax to do the same update:
 
698
</P><PRE
 
699
CLASS="PROGRAMLISTING"
 
700
>UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT)
 
701
  WHERE city = 'San Francisco' AND date = '2003-07-03';</PRE
 
702
><P>
 
703
  </P
 
704
><P
 
705
>   Increment the sales count of the salesperson who manages the
 
706
   account for Acme Corporation, using the <TT
 
707
CLASS="LITERAL"
 
708
>FROM</TT
 
709
>
 
710
   clause syntax:
 
711
</P><PRE
 
712
CLASS="PROGRAMLISTING"
 
713
>UPDATE employees SET sales_count = sales_count + 1 FROM accounts
 
714
  WHERE accounts.name = 'Acme Corporation'
 
715
  AND employees.id = accounts.sales_person;</PRE
 
716
><P>
 
717
  </P
 
718
><P
 
719
>   Perform the same operation, using a sub-select in the
 
720
   <TT
 
721
CLASS="LITERAL"
 
722
>WHERE</TT
 
723
> clause:
 
724
</P><PRE
 
725
CLASS="PROGRAMLISTING"
 
726
>UPDATE employees SET sales_count = sales_count + 1 WHERE id =
 
727
  (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');</PRE
 
728
><P>
 
729
  </P
 
730
><P
 
731
>   Attempt to insert a new stock item along with the quantity of stock. If
 
732
   the item already exists, instead update the stock count of the existing
 
733
   item. To do this without failing the entire transaction, use savepoints:
 
734
</P><PRE
 
735
CLASS="PROGRAMLISTING"
 
736
>BEGIN;
 
737
-- other operations
 
738
SAVEPOINT sp1;
 
739
INSERT INTO wines VALUES('Chateau Lafite 2003', '24');
 
740
-- Assume the above fails because of a unique key violation,
 
741
-- so now we issue these commands:
 
742
ROLLBACK TO sp1;
 
743
UPDATE wines SET stock = stock + 24 WHERE winename = 'Chateau Lafite 2003';
 
744
-- continue with other operations, and eventually
 
745
COMMIT;</PRE
 
746
><P>
 
747
  </P
 
748
><P
 
749
>   Change the <TT
 
750
CLASS="STRUCTFIELD"
 
751
>kind</TT
 
752
> column of the table
 
753
   <TT
 
754
CLASS="STRUCTNAME"
 
755
>films</TT
 
756
> in the row on which the cursor
 
757
   <TT
 
758
CLASS="LITERAL"
 
759
>c_films</TT
 
760
> is currently positioned:
 
761
</P><PRE
 
762
CLASS="PROGRAMLISTING"
 
763
>UPDATE films SET kind = 'Dramatic' WHERE CURRENT OF c_films;</PRE
 
764
><P>
 
765
  </P
 
766
></DIV
 
767
><DIV
 
768
CLASS="REFSECT1"
 
769
><A
 
770
NAME="AEN76139"
 
771
></A
 
772
><H2
 
773
>Compatibility</H2
 
774
><P
 
775
>   This command conforms to the <ACRONYM
 
776
CLASS="ACRONYM"
 
777
>SQL</ACRONYM
 
778
> standard, except
 
779
   that the <TT
 
780
CLASS="LITERAL"
 
781
>FROM</TT
 
782
> and <TT
 
783
CLASS="LITERAL"
 
784
>RETURNING</TT
 
785
> clauses
 
786
   are <SPAN
 
787
CLASS="PRODUCTNAME"
 
788
>PostgreSQL</SPAN
 
789
> extensions, as is the ability
 
790
   to use <TT
 
791
CLASS="LITERAL"
 
792
>WITH</TT
 
793
> with <TT
 
794
CLASS="COMMAND"
 
795
>UPDATE</TT
 
796
>.
 
797
  </P
 
798
><P
 
799
>   According to the standard, the column-list syntax should allow a list
 
800
   of columns to be assigned from a single row-valued expression, such
 
801
   as a sub-select:
 
802
</P><PRE
 
803
CLASS="PROGRAMLISTING"
 
804
>UPDATE accounts SET (contact_last_name, contact_first_name) =
 
805
    (SELECT last_name, first_name FROM salesmen
 
806
     WHERE salesmen.id = accounts.sales_id);</PRE
 
807
><P>
 
808
   This is not currently implemented &mdash; the source must be a list
 
809
   of independent expressions.
 
810
  </P
 
811
><P
 
812
>   Some other database systems offer a <TT
 
813
CLASS="LITERAL"
 
814
>FROM</TT
 
815
> option in which
 
816
   the target table is supposed to be listed again within <TT
 
817
CLASS="LITERAL"
 
818
>FROM</TT
 
819
>.
 
820
   That is not how <SPAN
 
821
CLASS="PRODUCTNAME"
 
822
>PostgreSQL</SPAN
 
823
> interprets
 
824
   <TT
 
825
CLASS="LITERAL"
 
826
>FROM</TT
 
827
>.  Be careful when porting applications that use this
 
828
   extension.
 
829
  </P
 
830
></DIV
 
831
><DIV
 
832
CLASS="NAVFOOTER"
 
833
><HR
 
834
ALIGN="LEFT"
 
835
WIDTH="100%"><TABLE
 
836
SUMMARY="Footer navigation table"
 
837
WIDTH="100%"
 
838
BORDER="0"
 
839
CELLPADDING="0"
 
840
CELLSPACING="0"
 
841
><TR
 
842
><TD
 
843
WIDTH="33%"
 
844
ALIGN="left"
 
845
VALIGN="top"
 
846
><A
 
847
HREF="sql-unlisten.html"
 
848
ACCESSKEY="P"
 
849
>Prev</A
 
850
></TD
 
851
><TD
 
852
WIDTH="34%"
 
853
ALIGN="center"
 
854
VALIGN="top"
 
855
><A
 
856
HREF="index.html"
 
857
ACCESSKEY="H"
 
858
>Home</A
 
859
></TD
 
860
><TD
 
861
WIDTH="33%"
 
862
ALIGN="right"
 
863
VALIGN="top"
 
864
><A
 
865
HREF="sql-vacuum.html"
 
866
ACCESSKEY="N"
 
867
>Next</A
 
868
></TD
 
869
></TR
 
870
><TR
 
871
><TD
 
872
WIDTH="33%"
 
873
ALIGN="left"
 
874
VALIGN="top"
 
875
>UNLISTEN</TD
 
876
><TD
 
877
WIDTH="34%"
 
878
ALIGN="center"
 
879
VALIGN="top"
 
880
><A
 
881
HREF="sql-commands.html"
 
882
ACCESSKEY="U"
 
883
>Up</A
 
884
></TD
 
885
><TD
 
886
WIDTH="33%"
 
887
ALIGN="right"
 
888
VALIGN="top"
 
889
>VACUUM</TD
 
890
></TR
 
891
></TABLE
 
892
></DIV
 
893
></BODY
 
894
></HTML
 
895
>
 
 
b'\\ No newline at end of file'