2003-08-26 20:32:23 +02:00
|
|
|
--
|
|
|
|
-- UPDATE ... SET <col> = DEFAULT;
|
|
|
|
--
|
|
|
|
|
|
|
|
CREATE TABLE update_test (
|
|
|
|
a INT DEFAULT 10,
|
|
|
|
b INT
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO update_test VALUES (5, 10);
|
|
|
|
INSERT INTO update_test VALUES (10, 15);
|
|
|
|
|
|
|
|
SELECT * FROM update_test;
|
|
|
|
|
|
|
|
UPDATE update_test SET a = DEFAULT, b = DEFAULT;
|
|
|
|
|
|
|
|
SELECT * FROM update_test;
|
|
|
|
|
2006-01-22 06:20:35 +01:00
|
|
|
-- aliases for the UPDATE target table
|
|
|
|
UPDATE update_test AS t SET b = 10 WHERE t.a = 10;
|
|
|
|
|
|
|
|
SELECT * FROM update_test;
|
|
|
|
|
|
|
|
UPDATE update_test t SET b = t.b + 10 WHERE t.a = 10;
|
|
|
|
|
|
|
|
SELECT * FROM update_test;
|
|
|
|
|
2006-08-03 16:54:44 +02:00
|
|
|
--
|
|
|
|
-- Test VALUES in FROM
|
|
|
|
--
|
|
|
|
|
|
|
|
UPDATE update_test SET a=v.i FROM (VALUES(100, 20)) AS v(i, j)
|
|
|
|
WHERE update_test.b = v.j;
|
|
|
|
|
|
|
|
SELECT * FROM update_test;
|
|
|
|
|
2006-01-22 06:20:35 +01:00
|
|
|
-- if an alias for the target table is specified, don't allow references
|
|
|
|
-- to the original table name
|
|
|
|
BEGIN;
|
|
|
|
SET LOCAL add_missing_from = false;
|
|
|
|
UPDATE update_test AS t SET b = update_test.b + 10 WHERE t.a = 10;
|
|
|
|
ROLLBACK;
|
|
|
|
|
2005-04-07 17:23:06 +02:00
|
|
|
DROP TABLE update_test;
|