mirror of https://github.com/citusdata/citus.git
Add regression tests for RETURNING.
parent
cccba66f24
commit
4549e06884
|
@ -97,6 +97,13 @@ SELECT COUNT(*) FROM limit_orders WHERE id = 32743;
|
||||||
1
|
1
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- basic single-row INSERT with RETURNING
|
||||||
|
INSERT INTO limit_orders VALUES (32744, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', 20.69) RETURNING *;
|
||||||
|
id | symbol | bidder_id | placed_at | kind | limit_price
|
||||||
|
-------+--------+-----------+--------------------------+------+-------------
|
||||||
|
32744 | AAPL | 9580 | Tue Oct 19 10:23:54 2004 | buy | 20.69
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- try a single-row INSERT with no shard to receive it
|
-- try a single-row INSERT with no shard to receive it
|
||||||
INSERT INTO insufficient_shards VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy',
|
INSERT INTO insufficient_shards VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy',
|
||||||
20.69);
|
20.69);
|
||||||
|
@ -173,6 +180,14 @@ INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy
|
||||||
ERROR: duplicate key value violates unique constraint "limit_orders_pkey_750001"
|
ERROR: duplicate key value violates unique constraint "limit_orders_pkey_750001"
|
||||||
DETAIL: Key (id)=(32743) already exists.
|
DETAIL: Key (id)=(32743) already exists.
|
||||||
CONTEXT: while executing command on localhost:57638
|
CONTEXT: while executing command on localhost:57638
|
||||||
|
-- INSERT violating primary key constraint, with RETURNING specified.
|
||||||
|
INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy', 0.58) RETURNING *;
|
||||||
|
ERROR: duplicate key value violates unique constraint "limit_orders_pkey_750001"
|
||||||
|
DETAIL: Key (id)=(32743) already exists.
|
||||||
|
CONTEXT: while executing command on localhost:57638
|
||||||
|
-- INSERT, with RETURNING specified, failing with a non-constraint error
|
||||||
|
INSERT INTO limit_orders VALUES (34153, 'LEE', 5994, '2001-04-16 03:37:28', 'buy', 0.58) RETURNING id / 0;
|
||||||
|
ERROR: could not modify any active placements
|
||||||
SET client_min_messages TO DEFAULT;
|
SET client_min_messages TO DEFAULT;
|
||||||
-- commands with non-constant partition values are unsupported
|
-- commands with non-constant partition values are unsupported
|
||||||
INSERT INTO limit_orders VALUES (random() * 100, 'ORCL', 152, '2011-08-25 11:50:45',
|
INSERT INTO limit_orders VALUES (random() * 100, 'ORCL', 152, '2011-08-25 11:50:45',
|
||||||
|
@ -215,6 +230,19 @@ SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
||||||
0
|
0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- test simple DELETE with RETURNING
|
||||||
|
DELETE FROM limit_orders WHERE id = 430 RETURNING *;
|
||||||
|
id | symbol | bidder_id | placed_at | kind | limit_price
|
||||||
|
-----+--------+-----------+--------------------------+------+-----------------
|
||||||
|
430 | IBM | 214 | Tue Jan 28 15:31:17 2003 | buy | 1.4142135623731
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT COUNT(*) FROM limit_orders WHERE id = 430;
|
||||||
|
count
|
||||||
|
-------
|
||||||
|
0
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- DELETE with expression in WHERE clause
|
-- DELETE with expression in WHERE clause
|
||||||
INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69);
|
INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69);
|
||||||
SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
||||||
|
@ -256,6 +284,13 @@ SELECT symbol FROM limit_orders WHERE id = 246;
|
||||||
GM
|
GM
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- simple UPDATE with RETURNING
|
||||||
|
UPDATE limit_orders SET symbol = 'GM' WHERE id = 246 RETURNING *;
|
||||||
|
id | symbol | bidder_id | placed_at | kind | limit_price
|
||||||
|
-----+--------+-----------+--------------------------+------+-------------
|
||||||
|
246 | GM | 162 | Mon Jul 02 16:32:15 2007 | sell | 20.69
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- expression UPDATE
|
-- expression UPDATE
|
||||||
UPDATE limit_orders SET bidder_id = 6 * 3 WHERE id = 246;
|
UPDATE limit_orders SET bidder_id = 6 * 3 WHERE id = 246;
|
||||||
SELECT bidder_id FROM limit_orders WHERE id = 246;
|
SELECT bidder_id FROM limit_orders WHERE id = 246;
|
||||||
|
@ -264,6 +299,13 @@ SELECT bidder_id FROM limit_orders WHERE id = 246;
|
||||||
18
|
18
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- expression UPDATE with RETURNING
|
||||||
|
UPDATE limit_orders SET bidder_id = 6 * 5 WHERE id = 246 RETURNING *;
|
||||||
|
id | symbol | bidder_id | placed_at | kind | limit_price
|
||||||
|
-----+--------+-----------+--------------------------+------+-------------
|
||||||
|
246 | GM | 30 | Mon Jul 02 16:32:15 2007 | sell | 20.69
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- multi-column UPDATE
|
-- multi-column UPDATE
|
||||||
UPDATE limit_orders SET (kind, limit_price) = ('buy', DEFAULT) WHERE id = 246;
|
UPDATE limit_orders SET (kind, limit_price) = ('buy', DEFAULT) WHERE id = 246;
|
||||||
SELECT kind, limit_price FROM limit_orders WHERE id = 246;
|
SELECT kind, limit_price FROM limit_orders WHERE id = 246;
|
||||||
|
@ -272,6 +314,13 @@ SELECT kind, limit_price FROM limit_orders WHERE id = 246;
|
||||||
buy | 0.00
|
buy | 0.00
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- multi-column UPDATE with RETURNING
|
||||||
|
UPDATE limit_orders SET (kind, limit_price) = ('buy', 999) WHERE id = 246 RETURNING *;
|
||||||
|
id | symbol | bidder_id | placed_at | kind | limit_price
|
||||||
|
-----+--------+-----------+--------------------------+------+-------------
|
||||||
|
246 | GM | 30 | Mon Jul 02 16:32:15 2007 | buy | 999
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- Test that on unique contraint violations, we fail fast
|
-- Test that on unique contraint violations, we fail fast
|
||||||
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
||||||
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
||||||
|
@ -362,7 +411,7 @@ DETAIL: Common table expressions are not supported in distributed modifications
|
||||||
SELECT symbol, bidder_id FROM limit_orders WHERE id = 246;
|
SELECT symbol, bidder_id FROM limit_orders WHERE id = 246;
|
||||||
symbol | bidder_id
|
symbol | bidder_id
|
||||||
--------+-----------
|
--------+-----------
|
||||||
GM | 18
|
GM | 30
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- updates referencing just a var are supported
|
-- updates referencing just a var are supported
|
||||||
|
@ -377,12 +426,51 @@ SELECT symbol, bidder_id FROM limit_orders WHERE id = 246;
|
||||||
gm | 247
|
gm | 247
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- IMMUTABLE functions are allowed -- even in returning
|
||||||
|
UPDATE limit_orders SET symbol = UPPER(symbol) WHERE id = 246 RETURNING id, LOWER(symbol), symbol;
|
||||||
|
id | lower | symbol
|
||||||
|
-----+-------+--------
|
||||||
|
246 | gm | GM
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- updates referencing non-IMMUTABLE functions are unsupported
|
-- updates referencing non-IMMUTABLE functions are unsupported
|
||||||
UPDATE limit_orders SET placed_at = now() WHERE id = 246;
|
UPDATE limit_orders SET placed_at = now() WHERE id = 246;
|
||||||
ERROR: functions used in modification queries on distributed tables must be marked IMMUTABLE
|
ERROR: functions used in modification queries on distributed tables must be marked IMMUTABLE
|
||||||
|
-- even in RETURNING
|
||||||
|
UPDATE limit_orders SET placed_at = placed_at WHERE id = 246 RETURNING NOW();
|
||||||
|
ERROR: functions used in modification queries on distributed tables must be marked IMMUTABLE
|
||||||
-- cursors are not supported
|
-- cursors are not supported
|
||||||
UPDATE limit_orders SET symbol = 'GM' WHERE CURRENT OF cursor_name;
|
UPDATE limit_orders SET symbol = 'GM' WHERE CURRENT OF cursor_name;
|
||||||
ERROR: distributed modifications must target exactly one shard
|
ERROR: distributed modifications must target exactly one shard
|
||||||
|
-- check that multi-row UPDATE/DELETEs with RETURNING work
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '1');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '2');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '3');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '4');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '5');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '6');
|
||||||
|
UPDATE multiple_hash SET data = data ||'-1' WHERE category = '0' RETURNING *;
|
||||||
|
category | data
|
||||||
|
----------+------
|
||||||
|
0 | 1-1
|
||||||
|
0 | 2-1
|
||||||
|
0 | 3-1
|
||||||
|
0 | 4-1
|
||||||
|
0 | 5-1
|
||||||
|
0 | 6-1
|
||||||
|
(6 rows)
|
||||||
|
|
||||||
|
DELETE FROM multiple_hash WHERE category = '0' RETURNING *;
|
||||||
|
category | data
|
||||||
|
----------+------
|
||||||
|
0 | 1-1
|
||||||
|
0 | 2-1
|
||||||
|
0 | 3-1
|
||||||
|
0 | 4-1
|
||||||
|
0 | 5-1
|
||||||
|
0 | 6-1
|
||||||
|
(6 rows)
|
||||||
|
|
||||||
-- ensure returned row counters are correct
|
-- ensure returned row counters are correct
|
||||||
\set QUIET off
|
\set QUIET off
|
||||||
INSERT INTO multiple_hash VALUES ('1', '1');
|
INSERT INTO multiple_hash VALUES ('1', '1');
|
||||||
|
@ -396,6 +484,13 @@ INSERT 0 1
|
||||||
INSERT INTO multiple_hash VALUES ('2', '2');
|
INSERT INTO multiple_hash VALUES ('2', '2');
|
||||||
INSERT 0 1
|
INSERT 0 1
|
||||||
INSERT INTO multiple_hash VALUES ('2', '3');
|
INSERT INTO multiple_hash VALUES ('2', '3');
|
||||||
|
INSERT 0 1
|
||||||
|
INSERT INTO multiple_hash VALUES ('2', '3') RETURNING *;
|
||||||
|
category | data
|
||||||
|
----------+------
|
||||||
|
2 | 3
|
||||||
|
(1 row)
|
||||||
|
|
||||||
INSERT 0 1
|
INSERT 0 1
|
||||||
-- check that update return the right number of rows
|
-- check that update return the right number of rows
|
||||||
-- one row
|
-- one row
|
||||||
|
@ -403,14 +498,24 @@ UPDATE multiple_hash SET data = data ||'-1' WHERE category = '1' AND data = '1';
|
||||||
UPDATE 1
|
UPDATE 1
|
||||||
-- three rows
|
-- three rows
|
||||||
UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1';
|
UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1';
|
||||||
|
UPDATE 3
|
||||||
|
-- three rows, with RETURNING
|
||||||
|
UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1' RETURNING category;
|
||||||
|
category
|
||||||
|
----------
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
(3 rows)
|
||||||
|
|
||||||
UPDATE 3
|
UPDATE 3
|
||||||
-- check
|
-- check
|
||||||
SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data;
|
SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data;
|
||||||
category | data
|
category | data
|
||||||
----------+-------
|
----------+---------
|
||||||
1 | 1-1-2
|
1 | 1-1-2-2
|
||||||
1 | 2-2
|
1 | 2-2-2
|
||||||
1 | 3-2
|
1 | 3-2-2
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- check that deletes return the right number of rows
|
-- check that deletes return the right number of rows
|
||||||
|
@ -419,8 +524,23 @@ DELETE FROM multiple_hash WHERE category = '2' AND data = '1';
|
||||||
DELETE 1
|
DELETE 1
|
||||||
-- two rows
|
-- two rows
|
||||||
DELETE FROM multiple_hash WHERE category = '2';
|
DELETE FROM multiple_hash WHERE category = '2';
|
||||||
DELETE 2
|
DELETE 3
|
||||||
|
-- three rows, with RETURNING
|
||||||
|
DELETE FROM multiple_hash WHERE category = '1' RETURNING category;
|
||||||
|
category
|
||||||
|
----------
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
(3 rows)
|
||||||
|
|
||||||
|
DELETE 3
|
||||||
-- check
|
-- check
|
||||||
|
SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data;
|
||||||
|
category | data
|
||||||
|
----------+------
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
SELECT * FROM multiple_hash WHERE category = '2' ORDER BY category, data;
|
SELECT * FROM multiple_hash WHERE category = '2' ORDER BY category, data;
|
||||||
category | data
|
category | data
|
||||||
----------+------
|
----------+------
|
||||||
|
|
|
@ -105,6 +105,23 @@ SELECT * FROM upsert_test;
|
||||||
1 | 5 | 872
|
1 | 5 | 872
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- Test upsert, with returning:
|
||||||
|
INSERT INTO upsert_test (part_key, other_col) VALUES (2, 2)
|
||||||
|
ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
RETURNING *;
|
||||||
|
part_key | other_col | third_col
|
||||||
|
----------+-----------+-----------
|
||||||
|
2 | 2 |
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
INSERT INTO upsert_test (part_key, other_col) VALUES (2, 2)
|
||||||
|
ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
RETURNING *;
|
||||||
|
part_key | other_col | third_col
|
||||||
|
----------+-----------+-----------
|
||||||
|
2 | 3 |
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- create another table
|
-- create another table
|
||||||
CREATE TABLE upsert_test_2
|
CREATE TABLE upsert_test_2
|
||||||
(
|
(
|
||||||
|
|
|
@ -138,6 +138,19 @@ SELECT * FROM upsert_test;
|
||||||
1 | 1 |
|
1 | 1 |
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- Test upsert, with returning:
|
||||||
|
INSERT INTO upsert_test (part_key, other_col) VALUES (2, 2)
|
||||||
|
ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
RETURNING *;
|
||||||
|
ERROR: syntax error at or near "ON"
|
||||||
|
LINE 2: ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
^
|
||||||
|
INSERT INTO upsert_test (part_key, other_col) VALUES (2, 2)
|
||||||
|
ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
RETURNING *;
|
||||||
|
ERROR: syntax error at or near "ON"
|
||||||
|
LINE 2: ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
^
|
||||||
-- create another table
|
-- create another table
|
||||||
CREATE TABLE upsert_test_2
|
CREATE TABLE upsert_test_2
|
||||||
(
|
(
|
||||||
|
|
|
@ -69,6 +69,9 @@ INSERT INTO limit_orders VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'bu
|
||||||
20.69);
|
20.69);
|
||||||
SELECT COUNT(*) FROM limit_orders WHERE id = 32743;
|
SELECT COUNT(*) FROM limit_orders WHERE id = 32743;
|
||||||
|
|
||||||
|
-- basic single-row INSERT with RETURNING
|
||||||
|
INSERT INTO limit_orders VALUES (32744, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy', 20.69) RETURNING *;
|
||||||
|
|
||||||
-- try a single-row INSERT with no shard to receive it
|
-- try a single-row INSERT with no shard to receive it
|
||||||
INSERT INTO insufficient_shards VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy',
|
INSERT INTO insufficient_shards VALUES (32743, 'AAPL', 9580, '2004-10-19 10:23:54', 'buy',
|
||||||
20.69);
|
20.69);
|
||||||
|
@ -118,10 +121,16 @@ INSERT INTO limit_orders VALUES (NULL, 'T', 975234, DEFAULT);
|
||||||
-- INSERT violating column constraint
|
-- INSERT violating column constraint
|
||||||
INSERT INTO limit_orders VALUES (18811, 'BUD', 14962, '2014-04-05 08:32:16', 'sell',
|
INSERT INTO limit_orders VALUES (18811, 'BUD', 14962, '2014-04-05 08:32:16', 'sell',
|
||||||
-5.00);
|
-5.00);
|
||||||
|
|
||||||
-- INSERT violating primary key constraint
|
-- INSERT violating primary key constraint
|
||||||
INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy', 0.58);
|
INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy', 0.58);
|
||||||
|
|
||||||
|
-- INSERT violating primary key constraint, with RETURNING specified.
|
||||||
|
INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy', 0.58) RETURNING *;
|
||||||
|
|
||||||
|
-- INSERT, with RETURNING specified, failing with a non-constraint error
|
||||||
|
INSERT INTO limit_orders VALUES (34153, 'LEE', 5994, '2001-04-16 03:37:28', 'buy', 0.58) RETURNING id / 0;
|
||||||
|
|
||||||
|
|
||||||
SET client_min_messages TO DEFAULT;
|
SET client_min_messages TO DEFAULT;
|
||||||
|
|
||||||
-- commands with non-constant partition values are unsupported
|
-- commands with non-constant partition values are unsupported
|
||||||
|
@ -154,6 +163,10 @@ SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
||||||
DELETE FROM limit_orders WHERE id = 246;
|
DELETE FROM limit_orders WHERE id = 246;
|
||||||
SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
||||||
|
|
||||||
|
-- test simple DELETE with RETURNING
|
||||||
|
DELETE FROM limit_orders WHERE id = 430 RETURNING *;
|
||||||
|
SELECT COUNT(*) FROM limit_orders WHERE id = 430;
|
||||||
|
|
||||||
-- DELETE with expression in WHERE clause
|
-- DELETE with expression in WHERE clause
|
||||||
INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69);
|
INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69);
|
||||||
SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
SELECT COUNT(*) FROM limit_orders WHERE id = 246;
|
||||||
|
@ -183,14 +196,23 @@ INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell'
|
||||||
UPDATE limit_orders SET symbol = 'GM' WHERE id = 246;
|
UPDATE limit_orders SET symbol = 'GM' WHERE id = 246;
|
||||||
SELECT symbol FROM limit_orders WHERE id = 246;
|
SELECT symbol FROM limit_orders WHERE id = 246;
|
||||||
|
|
||||||
|
-- simple UPDATE with RETURNING
|
||||||
|
UPDATE limit_orders SET symbol = 'GM' WHERE id = 246 RETURNING *;
|
||||||
|
|
||||||
-- expression UPDATE
|
-- expression UPDATE
|
||||||
UPDATE limit_orders SET bidder_id = 6 * 3 WHERE id = 246;
|
UPDATE limit_orders SET bidder_id = 6 * 3 WHERE id = 246;
|
||||||
SELECT bidder_id FROM limit_orders WHERE id = 246;
|
SELECT bidder_id FROM limit_orders WHERE id = 246;
|
||||||
|
|
||||||
|
-- expression UPDATE with RETURNING
|
||||||
|
UPDATE limit_orders SET bidder_id = 6 * 5 WHERE id = 246 RETURNING *;
|
||||||
|
|
||||||
-- multi-column UPDATE
|
-- multi-column UPDATE
|
||||||
UPDATE limit_orders SET (kind, limit_price) = ('buy', DEFAULT) WHERE id = 246;
|
UPDATE limit_orders SET (kind, limit_price) = ('buy', DEFAULT) WHERE id = 246;
|
||||||
SELECT kind, limit_price FROM limit_orders WHERE id = 246;
|
SELECT kind, limit_price FROM limit_orders WHERE id = 246;
|
||||||
|
|
||||||
|
-- multi-column UPDATE with RETURNING
|
||||||
|
UPDATE limit_orders SET (kind, limit_price) = ('buy', 999) WHERE id = 246 RETURNING *;
|
||||||
|
|
||||||
-- Test that on unique contraint violations, we fail fast
|
-- Test that on unique contraint violations, we fail fast
|
||||||
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
||||||
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
|
||||||
|
@ -285,12 +307,28 @@ UPDATE limit_orders SET symbol = LOWER(symbol) WHERE id = 246;
|
||||||
|
|
||||||
SELECT symbol, bidder_id FROM limit_orders WHERE id = 246;
|
SELECT symbol, bidder_id FROM limit_orders WHERE id = 246;
|
||||||
|
|
||||||
|
-- IMMUTABLE functions are allowed -- even in returning
|
||||||
|
UPDATE limit_orders SET symbol = UPPER(symbol) WHERE id = 246 RETURNING id, LOWER(symbol), symbol;
|
||||||
|
|
||||||
-- updates referencing non-IMMUTABLE functions are unsupported
|
-- updates referencing non-IMMUTABLE functions are unsupported
|
||||||
UPDATE limit_orders SET placed_at = now() WHERE id = 246;
|
UPDATE limit_orders SET placed_at = now() WHERE id = 246;
|
||||||
|
|
||||||
|
-- even in RETURNING
|
||||||
|
UPDATE limit_orders SET placed_at = placed_at WHERE id = 246 RETURNING NOW();
|
||||||
|
|
||||||
-- cursors are not supported
|
-- cursors are not supported
|
||||||
UPDATE limit_orders SET symbol = 'GM' WHERE CURRENT OF cursor_name;
|
UPDATE limit_orders SET symbol = 'GM' WHERE CURRENT OF cursor_name;
|
||||||
|
|
||||||
|
-- check that multi-row UPDATE/DELETEs with RETURNING work
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '1');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '2');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '3');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '4');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '5');
|
||||||
|
INSERT INTO multiple_hash VALUES ('0', '6');
|
||||||
|
|
||||||
|
UPDATE multiple_hash SET data = data ||'-1' WHERE category = '0' RETURNING *;
|
||||||
|
DELETE FROM multiple_hash WHERE category = '0' RETURNING *;
|
||||||
|
|
||||||
-- ensure returned row counters are correct
|
-- ensure returned row counters are correct
|
||||||
\set QUIET off
|
\set QUIET off
|
||||||
|
@ -300,12 +338,15 @@ INSERT INTO multiple_hash VALUES ('1', '3');
|
||||||
INSERT INTO multiple_hash VALUES ('2', '1');
|
INSERT INTO multiple_hash VALUES ('2', '1');
|
||||||
INSERT INTO multiple_hash VALUES ('2', '2');
|
INSERT INTO multiple_hash VALUES ('2', '2');
|
||||||
INSERT INTO multiple_hash VALUES ('2', '3');
|
INSERT INTO multiple_hash VALUES ('2', '3');
|
||||||
|
INSERT INTO multiple_hash VALUES ('2', '3') RETURNING *;
|
||||||
|
|
||||||
-- check that update return the right number of rows
|
-- check that update return the right number of rows
|
||||||
-- one row
|
-- one row
|
||||||
UPDATE multiple_hash SET data = data ||'-1' WHERE category = '1' AND data = '1';
|
UPDATE multiple_hash SET data = data ||'-1' WHERE category = '1' AND data = '1';
|
||||||
-- three rows
|
-- three rows
|
||||||
UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1';
|
UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1';
|
||||||
|
-- three rows, with RETURNING
|
||||||
|
UPDATE multiple_hash SET data = data ||'-2' WHERE category = '1' RETURNING category;
|
||||||
-- check
|
-- check
|
||||||
SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data;
|
SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data;
|
||||||
|
|
||||||
|
@ -314,5 +355,8 @@ SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data;
|
||||||
DELETE FROM multiple_hash WHERE category = '2' AND data = '1';
|
DELETE FROM multiple_hash WHERE category = '2' AND data = '1';
|
||||||
-- two rows
|
-- two rows
|
||||||
DELETE FROM multiple_hash WHERE category = '2';
|
DELETE FROM multiple_hash WHERE category = '2';
|
||||||
|
-- three rows, with RETURNING
|
||||||
|
DELETE FROM multiple_hash WHERE category = '1' RETURNING category;
|
||||||
-- check
|
-- check
|
||||||
|
SELECT * FROM multiple_hash WHERE category = '1' ORDER BY category, data;
|
||||||
SELECT * FROM multiple_hash WHERE category = '2' ORDER BY category, data;
|
SELECT * FROM multiple_hash WHERE category = '2' ORDER BY category, data;
|
||||||
|
|
|
@ -85,6 +85,15 @@ INSERT INTO upsert_test as ups_test (part_key, other_col) VALUES (1, 1) ON CONFL
|
||||||
-- see the results
|
-- see the results
|
||||||
SELECT * FROM upsert_test;
|
SELECT * FROM upsert_test;
|
||||||
|
|
||||||
|
-- Test upsert, with returning:
|
||||||
|
INSERT INTO upsert_test (part_key, other_col) VALUES (2, 2)
|
||||||
|
ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
|
INSERT INTO upsert_test (part_key, other_col) VALUES (2, 2)
|
||||||
|
ON CONFLICT (part_key) DO UPDATE SET other_col = 3
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
-- create another table
|
-- create another table
|
||||||
CREATE TABLE upsert_test_2
|
CREATE TABLE upsert_test_2
|
||||||
(
|
(
|
||||||
|
|
Loading…
Reference in New Issue