diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-11-20 11:14:58 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-11-20 11:14:58 +0000 |
commit | 31773f157bf8164364649b5f470f52dece0a4317 (patch) | |
tree | 33d0f7eef45303ab68cf08ab381ce5e5e36c5240 /yql/essentials/tests/postgresql/cases/truncate.sql | |
parent | 2c7938962d8689e175574fc1e817c05049f27905 (diff) | |
parent | eff600952d5dfe17942f38f510a8ac2b203bb3a5 (diff) | |
download | ydb-31773f157bf8164364649b5f470f52dece0a4317.tar.gz |
Merge branch 'rightlib' into mergelibs-241120-1113
Diffstat (limited to 'yql/essentials/tests/postgresql/cases/truncate.sql')
-rw-r--r-- | yql/essentials/tests/postgresql/cases/truncate.sql | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/yql/essentials/tests/postgresql/cases/truncate.sql b/yql/essentials/tests/postgresql/cases/truncate.sql new file mode 100644 index 0000000000..f76c95b9a7 --- /dev/null +++ b/yql/essentials/tests/postgresql/cases/truncate.sql @@ -0,0 +1,53 @@ +-- Test basic TRUNCATE functionality. +CREATE TABLE truncate_a (col1 integer primary key); +INSERT INTO truncate_a VALUES (1); +INSERT INTO truncate_a VALUES (2); +SELECT * FROM truncate_a; +-- Roll truncate back +BEGIN; +ROLLBACK; +SELECT * FROM truncate_a; +-- Commit the truncate this time +BEGIN; +COMMIT; +CREATE TABLE trunc_c (a serial PRIMARY KEY); +-- Add some data to verify that truncating actually works ... +INSERT INTO trunc_c VALUES (1); +INSERT INTO truncate_a VALUES (1); +-- Add data again to test TRUNCATE ... CASCADE +INSERT INTO trunc_c VALUES (1); +INSERT INTO truncate_a VALUES (1); +-- Test TRUNCATE with inheritance +CREATE TABLE trunc_f (col1 integer primary key); +INSERT INTO trunc_f VALUES (1); +INSERT INTO trunc_f VALUES (2); +BEGIN; +ROLLBACK; +BEGIN; +ROLLBACK; +BEGIN; +ROLLBACK; +BEGIN; +SELECT * FROM trunc_f; +ROLLBACK; +-- Test ON TRUNCATE triggers +CREATE TABLE trunc_trigger_test (f1 int, f2 text, f3 text); +CREATE TABLE trunc_trigger_log (tgop text, tglevel text, tgwhen text, + tgargv text, tgtable name, rowcount bigint); +-- basic before trigger +INSERT INTO trunc_trigger_test VALUES(1, 'foo', 'bar'), (2, 'baz', 'quux'); +SELECT count(*) as "Row count in test table" FROM trunc_trigger_test; +SELECT * FROM trunc_trigger_log; +-- same test with an after trigger +INSERT INTO trunc_trigger_test VALUES(1, 'foo', 'bar'), (2, 'baz', 'quux'); +SELECT * FROM trunc_trigger_log; +DROP TABLE trunc_trigger_test; +DROP TABLE trunc_trigger_log; +CREATE TABLE truncate_a (id serial, + id1 integer default nextval('truncate_a_id1')); +-- check rollback of a RESTART IDENTITY operation +BEGIN; +ROLLBACK; +DROP TABLE truncate_a; +SELECT nextval('truncate_a_id1'); -- fail, seq should have been dropped +CREATE TABLE truncprim (a int PRIMARY KEY); |