mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-20 05:17:00 +08:00
and DELETE. If specified, the alias must be used instead of the full table name. Also, the alias currently cannot be used in the SET clause of UPDATE. Patch from Atsushi Ogawa, various editorialization by Neil Conway. Along the way, make the rowtypes regression test pass if add_missing_from is enabled, and add a new (skeletal) regression test for DELETE.
36 lines
747 B
PL/PgSQL
36 lines
747 B
PL/PgSQL
--
|
|
-- 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;
|
|
|
|
-- 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;
|
|
|
|
-- 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;
|
|
|
|
DROP TABLE update_test;
|