update.sql 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --
  2. -- UPDATE syntax tests
  3. --
  4. CREATE TABLE update_test (
  5. a INT DEFAULT 10,
  6. b INT,
  7. c TEXT
  8. );
  9. CREATE TABLE upsert_test (
  10. a INT PRIMARY KEY,
  11. b TEXT
  12. );
  13. INSERT INTO update_test VALUES (5, 10, 'foo');
  14. INSERT INTO update_test(b, a) VALUES (15, 10);
  15. SELECT * FROM update_test;
  16. --
  17. -- Test multiple-set-clause syntax
  18. --
  19. INSERT INTO update_test SELECT a,b+1,c FROM update_test;
  20. -- Test ON CONFLICT DO UPDATE
  21. INSERT INTO upsert_test VALUES(1, 'Boo'), (3, 'Zoo');
  22. DROP TABLE update_test;
  23. DROP TABLE upsert_test;
  24. CREATE TABLE upsert_test_2 (b TEXT, a INT PRIMARY KEY);
  25. -- Create partitions intentionally in descending bound order, so as to test
  26. -- that update-row-movement works with the leaf partitions not in bound order.
  27. CREATE TABLE part_b_20_b_30 (e varchar, c numeric, a text, b bigint, d int);
  28. CREATE TABLE part_c_1_100 (e varchar, d int, c numeric, b bigint, a text);
  29. \set init_range_parted 'truncate range_parted; insert into range_parted VALUES (''a'', 1, 1, 1), (''a'', 10, 200, 1), (''b'', 12, 96, 1), (''b'', 13, 97, 2), (''b'', 15, 105, 16), (''b'', 17, 105, 19)'
  30. \set show_data 'select tableoid::regclass::text COLLATE "C" partname, * from range_parted ORDER BY 1, 2, 3, 4, 5, 6'
  31. -- Common table needed for multiple test scenarios.
  32. CREATE TABLE mintab(c1 int);
  33. INSERT into mintab VALUES (120);
  34. DROP TABLE mintab;
  35. CREATE TABLE sub_part1(b int, c int8, a numeric);
  36. CREATE TABLE sub_part2(b int, c int8, a numeric);
  37. CREATE TABLE list_part1(a numeric, b int, c int8);
  38. -- UPDATE partition-key with FROM clause. If join produces multiple output
  39. -- rows for the same row to be modified, we should tuple-route the row only
  40. -- once. There should not be any rows inserted.
  41. CREATE TABLE non_parted (id int);
  42. INSERT into non_parted VALUES (1), (1), (1), (2), (2), (2), (3), (3), (3);
  43. DROP TABLE non_parted;