~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-updates

« back to all changes in this revision

Viewing changes to src/test/regress/sql/update.sql

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- UPDATE syntax tests
 
3
--
 
4
 
 
5
CREATE TABLE update_test (
 
6
    a   INT DEFAULT 10,
 
7
    b   INT,
 
8
    c   TEXT
 
9
);
 
10
 
 
11
INSERT INTO update_test VALUES (5, 10, 'foo');
 
12
INSERT INTO update_test(b, a) VALUES (15, 10);
 
13
 
 
14
SELECT * FROM update_test;
 
15
 
 
16
UPDATE update_test SET a = DEFAULT, b = DEFAULT;
 
17
 
 
18
SELECT * FROM update_test;
 
19
 
 
20
-- aliases for the UPDATE target table
 
21
UPDATE update_test AS t SET b = 10 WHERE t.a = 10;
 
22
 
 
23
SELECT * FROM update_test;
 
24
 
 
25
UPDATE update_test t SET b = t.b + 10 WHERE t.a = 10;
 
26
 
 
27
SELECT * FROM update_test;
 
28
 
 
29
--
 
30
-- Test VALUES in FROM
 
31
--
 
32
 
 
33
UPDATE update_test SET a=v.i FROM (VALUES(100, 20)) AS v(i, j)
 
34
  WHERE update_test.b = v.j;
 
35
 
 
36
SELECT * FROM update_test;
 
37
 
 
38
--
 
39
-- Test multiple-set-clause syntax
 
40
--
 
41
 
 
42
UPDATE update_test SET (c,b,a) = ('bugle', b+11, DEFAULT) WHERE c = 'foo';
 
43
SELECT * FROM update_test;
 
44
UPDATE update_test SET (c,b) = ('car', a+b), a = a + 1 WHERE a = 10;
 
45
SELECT * FROM update_test;
 
46
-- fail, multi assignment to same column:
 
47
UPDATE update_test SET (c,b) = ('car', a+b), b = a + 1 WHERE a = 10;
 
48
 
 
49
-- XXX this should work, but doesn't yet:
 
50
UPDATE update_test SET (a,b) = (select a,b FROM update_test where c = 'foo')
 
51
  WHERE a = 10;
 
52
 
 
53
-- if an alias for the target table is specified, don't allow references
 
54
-- to the original table name
 
55
BEGIN;
 
56
SET LOCAL add_missing_from = false;
 
57
UPDATE update_test AS t SET b = update_test.b + 10 WHERE t.a = 10;
 
58
ROLLBACK;
 
59
 
 
60
DROP TABLE update_test;