5 SET pg_stat_statements.track_utility = FALSE;
7 CREATE TEMP TABLE pgss_dml_tab (a int, b char(20));
9 INSERT INTO pgss_dml_tab VALUES(generate_series(1, 10), 'aaa');
10 UPDATE pgss_dml_tab SET b = 'bbb' WHERE a > 7;
11 DELETE FROM pgss_dml_tab WHERE a > 9;
13 -- explicit transaction
15 UPDATE pgss_dml_tab SET b = '111' WHERE a = 1 ;
19 UPDATE pgss_dml_tab SET b = '222' WHERE a = 2 \;
22 UPDATE pgss_dml_tab SET b = '333' WHERE a = 3 \;
23 UPDATE pgss_dml_tab SET b = '444' WHERE a = 4 ;
26 UPDATE pgss_dml_tab SET b = '555' WHERE a = 5 \;
27 UPDATE pgss_dml_tab SET b = '666' WHERE a = 6 \;
31 INSERT INTO pgss_dml_tab (a, b) VALUES (1, 'a'), (2, 'b'), (3, 'c');
33 -- SELECT with constants
34 SELECT * FROM pgss_dml_tab WHERE a > 5 ORDER BY a ;
41 -- these two need to be done on a different table
42 -- SELECT without constants
43 SELECT * FROM pgss_dml_tab ORDER BY a;
45 -- SELECT with IN clause
46 SELECT * FROM pgss_dml_tab WHERE a IN (1, 2, 3, 4, 5);
48 SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
49 SELECT pg_stat_statements_reset() IS NOT NULL AS t;
52 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a AND st.a >= 4)
53 WHEN MATCHED THEN UPDATE SET b = st.b || st.a::text;
54 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a AND st.a >= 4)
55 WHEN MATCHED THEN UPDATE SET b = pgss_dml_tab.b || st.a::text;
56 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a AND st.a >= 4)
57 WHEN MATCHED AND length(st.b) > 1 THEN UPDATE SET b = pgss_dml_tab.b || st.a::text;
58 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a)
59 WHEN NOT MATCHED THEN INSERT (a, b) VALUES (0, NULL);
60 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a)
61 WHEN NOT MATCHED THEN INSERT VALUES (0, NULL); -- same as above
62 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a)
63 WHEN NOT MATCHED THEN INSERT (b, a) VALUES (NULL, 0);
64 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a)
65 WHEN NOT MATCHED THEN INSERT (a) VALUES (0);
66 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a AND st.a >= 4)
67 WHEN MATCHED THEN DELETE;
68 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a AND st.a >= 4)
69 WHEN MATCHED THEN DO NOTHING;
70 MERGE INTO pgss_dml_tab USING pgss_dml_tab st ON (st.a = pgss_dml_tab.a AND st.a >= 4)
71 WHEN NOT MATCHED THEN DO NOTHING;
73 DROP TABLE pgss_dml_tab;
75 SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
77 -- check that [temp] table relation extensions are tracked as writes
78 CREATE TABLE pgss_extend_tab (a int, b text);
79 CREATE TEMP TABLE pgss_extend_temp_tab (a int, b text);
80 SELECT pg_stat_statements_reset() IS NOT NULL AS t;
81 INSERT INTO pgss_extend_tab (a, b) SELECT generate_series(1, 1000), 'something';
82 INSERT INTO pgss_extend_temp_tab (a, b) SELECT generate_series(1, 1000), 'something';
85 pg_relation_size('pgss_extend_tab') / current_setting('block_size')::int8 AS rel_size,
86 pg_relation_size('pgss_extend_temp_tab') / current_setting('block_size')::int8 AS temp_rel_size
89 SUM(local_blks_written) >= (SELECT temp_rel_size FROM sizes) AS temp_written_ok,
90 SUM(local_blks_dirtied) >= (SELECT temp_rel_size FROM sizes) AS temp_dirtied_ok,
91 SUM(shared_blks_written) >= (SELECT rel_size FROM sizes) AS written_ok,
92 SUM(shared_blks_dirtied) >= (SELECT rel_size FROM sizes) AS dirtied_ok
93 FROM pg_stat_statements;
95 SELECT pg_stat_statements_reset() IS NOT NULL AS t;