--
|
-- one_c_temp_memory_catalog_define_relation
|
--
|
|
SET client_min_messages = warning;
|
|
SET enable_temp_memory_catalog = off;
|
|
CREATE TEMP TABLE tmc_defrel_phys(
|
id integer NOT NULL,
|
value integer DEFAULT 5,
|
CHECK (value > 0)
|
);
|
|
WITH phys_oid AS (
|
SELECT 'pg_temp.tmc_defrel_phys'::regclass AS oid
|
)
|
SELECT
|
(SELECT count(*) FROM pg_catalog.pg_class WHERE oid = phys_oid.oid) AS pg_class_rows,
|
(SELECT count(*) > 0
|
FROM pg_catalog.pg_attribute
|
WHERE attrelid = phys_oid.oid
|
AND attnum > 0
|
AND NOT attisdropped) AS pg_attribute_rows_present,
|
(SELECT count(*) > 0
|
FROM pg_catalog.pg_attrdef
|
WHERE adrelid = phys_oid.oid) AS pg_attrdef_rows_present,
|
(SELECT count(*) > 0
|
FROM pg_catalog.pg_constraint
|
WHERE conrelid = phys_oid.oid) AS pg_constraint_rows_present
|
FROM phys_oid;
|
|
INSERT INTO pg_temp.tmc_defrel_phys(id, value)
|
VALUES (1, DEFAULT), (2, 9);
|
|
SELECT id, value
|
FROM pg_temp.tmc_defrel_phys
|
ORDER BY id;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_defrel_mem(
|
id integer NOT NULL,
|
value integer DEFAULT 7,
|
CHECK (value > 0)
|
);
|
|
SELECT to_regclass('pg_temp.tmc_defrel_mem') IS NOT NULL AS mem_table_visible;
|
|
SET enable_temp_memory_catalog = off;
|
|
INSERT INTO pg_temp.tmc_defrel_mem(id, value)
|
VALUES (10, DEFAULT), (11, 8);
|
|
SELECT id, value
|
FROM pg_temp.tmc_defrel_mem
|
ORDER BY id;
|
|
DO $$
|
DECLARE
|
check_failed boolean := false;
|
BEGIN
|
BEGIN
|
INSERT INTO pg_temp.tmc_defrel_mem(id, value)
|
VALUES (12, 0);
|
EXCEPTION
|
WHEN check_violation THEN
|
check_failed := true;
|
END;
|
|
IF NOT check_failed THEN
|
RAISE EXCEPTION 'tmc_defrel_mem check constraint did not fire';
|
END IF;
|
END;
|
$$;
|
|
WITH mem_oid AS (
|
SELECT to_regclass('pg_temp.tmc_defrel_mem') AS oid
|
)
|
SELECT
|
(SELECT count(*) FROM pg_catalog.pg_class WHERE oid = mem_oid.oid) AS pg_class_rows,
|
(SELECT count(*) FROM pg_catalog.pg_attribute
|
WHERE attrelid = mem_oid.oid
|
AND attnum > 0
|
AND NOT attisdropped) AS pg_attribute_rows,
|
(SELECT count(*) FROM pg_catalog.pg_attrdef
|
WHERE adrelid = mem_oid.oid) AS pg_attrdef_rows,
|
(SELECT count(*) FROM pg_catalog.pg_constraint
|
WHERE conrelid = mem_oid.oid) AS pg_constraint_rows
|
FROM mem_oid;
|
|
SET enable_temp_memory_catalog = on;
|
|
WITH phys_oid AS (
|
SELECT 'pg_temp.tmc_defrel_phys'::regclass AS oid
|
)
|
SELECT
|
(SELECT count(*) FROM pg_catalog.pg_class WHERE oid = phys_oid.oid) AS pg_class_rows,
|
(SELECT count(*) > 0
|
FROM pg_catalog.pg_attribute
|
WHERE attrelid = phys_oid.oid
|
AND attnum > 0
|
AND NOT attisdropped) AS pg_attribute_rows_present,
|
(SELECT count(*) > 0
|
FROM pg_catalog.pg_attrdef
|
WHERE adrelid = phys_oid.oid) AS pg_attrdef_rows_present,
|
(SELECT count(*) > 0
|
FROM pg_catalog.pg_constraint
|
WHERE conrelid = phys_oid.oid) AS pg_constraint_rows_present
|
FROM phys_oid;
|
|
CREATE TEMP VIEW tmc_defrel_view AS
|
SELECT 41::integer AS answer;
|
|
SET enable_temp_memory_catalog = off;
|
|
SELECT answer
|
FROM pg_temp.tmc_defrel_view;
|
|
WITH view_oid AS (
|
SELECT to_regclass('pg_temp.tmc_defrel_view') AS oid
|
)
|
SELECT
|
to_regclass('pg_temp.tmc_defrel_view') IS NOT NULL AS view_visible,
|
(SELECT count(*) FROM pg_catalog.pg_class WHERE oid = view_oid.oid) AS pg_class_rows,
|
(SELECT count(*) FROM pg_catalog.pg_attribute
|
WHERE attrelid = view_oid.oid
|
AND attnum > 0
|
AND NOT attisdropped) AS pg_attribute_rows
|
FROM view_oid;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_defrel_part(
|
id integer NOT NULL,
|
value integer,
|
CHECK (value > 0)
|
) PARTITION BY RANGE (id);
|
|
CREATE TEMP TABLE tmc_defrel_part_1
|
PARTITION OF pg_temp.tmc_defrel_part
|
FOR VALUES FROM (0) TO (100);
|
|
SET enable_temp_memory_catalog = off;
|
|
INSERT INTO pg_temp.tmc_defrel_part(id, value)
|
VALUES (5, 15);
|
|
SELECT id, value
|
FROM pg_temp.tmc_defrel_part_1;
|
|
WITH parent_oid AS (
|
SELECT to_regclass('pg_temp.tmc_defrel_part') AS oid
|
),
|
child_oid AS (
|
SELECT to_regclass('pg_temp.tmc_defrel_part_1') AS oid
|
)
|
SELECT
|
(SELECT count(*) FROM pg_catalog.pg_class WHERE oid = parent_oid.oid) AS parent_pg_class_rows,
|
(SELECT count(*) FROM pg_catalog.pg_attribute
|
WHERE attrelid = parent_oid.oid
|
AND attnum > 0
|
AND NOT attisdropped) AS parent_pg_attribute_rows,
|
(SELECT count(*) FROM pg_catalog.pg_partitioned_table
|
WHERE partrelid = parent_oid.oid) AS parent_pg_partitioned_table_rows,
|
(SELECT count(*) FROM pg_catalog.pg_class WHERE oid = child_oid.oid) AS child_pg_class_rows,
|
(SELECT count(*) FROM pg_catalog.pg_attribute
|
WHERE attrelid = child_oid.oid
|
AND attnum > 0
|
AND NOT attisdropped) AS child_pg_attribute_rows,
|
(SELECT count(*) FROM pg_catalog.pg_inherits
|
WHERE inhrelid = child_oid.oid
|
AND inhparent = parent_oid.oid) AS pg_inherits_rows
|
FROM parent_oid, child_oid;
|
|
SET enable_temp_memory_catalog = on;
|
|
BEGIN;
|
SAVEPOINT tmc_defrel_s;
|
|
CREATE TEMP TABLE tmc_defrel_rb(
|
id integer NOT NULL,
|
value integer DEFAULT 9,
|
CONSTRAINT tmc_defrel_rb_value_check CHECK (value > 0)
|
);
|
|
SELECT to_regclass('pg_temp.tmc_defrel_rb') IS NOT NULL AS rb_visible_inside;
|
|
ROLLBACK TO SAVEPOINT tmc_defrel_s;
|
RELEASE SAVEPOINT tmc_defrel_s;
|
COMMIT;
|
|
WITH phys AS (
|
SELECT oid
|
FROM pg_catalog.pg_class
|
WHERE relnamespace = pg_my_temp_schema()
|
AND relname = 'tmc_defrel_rb'
|
)
|
SELECT
|
to_regclass('pg_temp.tmc_defrel_rb') IS NULL AS rb_missing_after,
|
(SELECT count(*) FROM phys) AS pg_class_rows,
|
(SELECT count(*) FROM pg_catalog.pg_attrdef
|
WHERE adrelid IN (SELECT oid FROM phys)) AS pg_attrdef_rows,
|
(SELECT count(*) FROM pg_catalog.pg_constraint
|
WHERE conname = 'tmc_defrel_rb_value_check') AS pg_constraint_rows
|
;
|
|
DROP VIEW pg_temp.tmc_defrel_view;
|
DROP TABLE pg_temp.tmc_defrel_part;
|
DROP TABLE pg_temp.tmc_defrel_mem;
|
DROP TABLE pg_temp.tmc_defrel_phys;
|
|
RESET enable_temp_memory_catalog;
|