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

« back to all changes in this revision

Viewing changes to src/test/regress/expected/update.out

  • 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
--
 
2
-- UPDATE syntax tests
 
3
--
 
4
CREATE TABLE update_test (
 
5
    a   INT DEFAULT 10,
 
6
    b   INT,
 
7
    c   TEXT
 
8
);
 
9
INSERT INTO update_test VALUES (5, 10, 'foo');
 
10
INSERT INTO update_test(b, a) VALUES (15, 10);
 
11
SELECT * FROM update_test;
 
12
 a  | b  |  c  
 
13
----+----+-----
 
14
  5 | 10 | foo
 
15
 10 | 15 | 
 
16
(2 rows)
 
17
 
 
18
UPDATE update_test SET a = DEFAULT, b = DEFAULT;
 
19
SELECT * FROM update_test;
 
20
 a  | b |  c  
 
21
----+---+-----
 
22
 10 |   | foo
 
23
 10 |   | 
 
24
(2 rows)
 
25
 
 
26
-- aliases for the UPDATE target table
 
27
UPDATE update_test AS t SET b = 10 WHERE t.a = 10;
 
28
SELECT * FROM update_test;
 
29
 a  | b  |  c  
 
30
----+----+-----
 
31
 10 | 10 | foo
 
32
 10 | 10 | 
 
33
(2 rows)
 
34
 
 
35
UPDATE update_test t SET b = t.b + 10 WHERE t.a = 10;
 
36
SELECT * FROM update_test;
 
37
 a  | b  |  c  
 
38
----+----+-----
 
39
 10 | 20 | foo
 
40
 10 | 20 | 
 
41
(2 rows)
 
42
 
 
43
--
 
44
-- Test VALUES in FROM
 
45
--
 
46
UPDATE update_test SET a=v.i FROM (VALUES(100, 20)) AS v(i, j)
 
47
  WHERE update_test.b = v.j;
 
48
SELECT * FROM update_test;
 
49
  a  | b  |  c  
 
50
-----+----+-----
 
51
 100 | 20 | foo
 
52
 100 | 20 | 
 
53
(2 rows)
 
54
 
 
55
--
 
56
-- Test multiple-set-clause syntax
 
57
--
 
58
UPDATE update_test SET (c,b,a) = ('bugle', b+11, DEFAULT) WHERE c = 'foo';
 
59
SELECT * FROM update_test;
 
60
  a  | b  |   c   
 
61
-----+----+-------
 
62
 100 | 20 | 
 
63
  10 | 31 | bugle
 
64
(2 rows)
 
65
 
 
66
UPDATE update_test SET (c,b) = ('car', a+b), a = a + 1 WHERE a = 10;
 
67
SELECT * FROM update_test;
 
68
  a  | b  |  c  
 
69
-----+----+-----
 
70
 100 | 20 | 
 
71
  11 | 41 | car
 
72
(2 rows)
 
73
 
 
74
-- fail, multi assignment to same column:
 
75
UPDATE update_test SET (c,b) = ('car', a+b), b = a + 1 WHERE a = 10;
 
76
ERROR:  multiple assignments to same column "b"
 
77
-- XXX this should work, but doesn't yet:
 
78
UPDATE update_test SET (a,b) = (select a,b FROM update_test where c = 'foo')
 
79
  WHERE a = 10;
 
80
ERROR:  syntax error at or near "select"
 
81
LINE 1: UPDATE update_test SET (a,b) = (select a,b FROM update_test ...
 
82
                                        ^
 
83
-- if an alias for the target table is specified, don't allow references
 
84
-- to the original table name
 
85
UPDATE update_test AS t SET b = update_test.b + 10 WHERE t.a = 10;
 
86
ERROR:  invalid reference to FROM-clause entry for table "update_test"
 
87
LINE 1: UPDATE update_test AS t SET b = update_test.b + 10 WHERE t.a...
 
88
                                        ^
 
89
HINT:  Perhaps you meant to reference the table alias "t".
 
90
-- Make sure that we can update to a TOASTed value.
 
91
UPDATE update_test SET c = repeat('x', 10000) WHERE c = 'car';
 
92
SELECT a, b, char_length(c) FROM update_test;
 
93
  a  | b  | char_length 
 
94
-----+----+-------------
 
95
 100 | 20 |            
 
96
  11 | 41 |       10000
 
97
(2 rows)
 
98
 
 
99
DROP TABLE update_test;