--
|
-- one_c_temp_memory_catalog_ddl
|
--
|
|
SET client_min_messages = warning;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_ddl_rename(
|
n integer,
|
keep integer
|
);
|
|
INSERT INTO pg_temp.tmc_ddl_rename
|
VALUES (11, 22);
|
|
SET enable_temp_memory_catalog = off;
|
|
ALTER TABLE pg_temp.tmc_ddl_rename
|
RENAME COLUMN n TO n2;
|
|
SELECT n2, keep
|
FROM pg_temp.tmc_ddl_rename;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
rowcount bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_ddl_rename');
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_ddl_rename is missing';
|
END IF;
|
|
SELECT count(*) INTO rowcount
|
FROM pg_catalog.pg_attribute
|
WHERE attrelid = rel_oid
|
AND attnum > 0
|
AND NOT attisdropped;
|
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_attribute rowcount for tmc_ddl_rename: got %, expected 0',
|
rowcount;
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.tmc_ddl_rename;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_ddl_rename_rb(
|
original_name integer
|
);
|
|
INSERT INTO pg_temp.tmc_ddl_rename_rb
|
VALUES (7);
|
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
SAVEPOINT tmc_rename_s;
|
|
ALTER TABLE pg_temp.tmc_ddl_rename_rb
|
RENAME COLUMN original_name TO temporary_name;
|
|
SELECT temporary_name
|
FROM pg_temp.tmc_ddl_rename_rb;
|
|
ROLLBACK TO SAVEPOINT tmc_rename_s;
|
RELEASE SAVEPOINT tmc_rename_s;
|
COMMIT;
|
|
SELECT original_name
|
FROM pg_temp.tmc_ddl_rename_rb;
|
|
DROP TABLE pg_temp.tmc_ddl_rename_rb;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_ddl_type(
|
a integer,
|
b integer
|
);
|
|
INSERT INTO pg_temp.tmc_ddl_type
|
VALUES (1, 2);
|
|
SELECT pg_typeof(a)::text AS a_type, a, b
|
FROM pg_temp.tmc_ddl_type;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
rowcount bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_ddl_type');
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_ddl_type is missing before ALTER TYPE';
|
END IF;
|
|
SELECT count(*) INTO rowcount
|
FROM pg_catalog.pg_depend
|
WHERE classid = 'pg_catalog.pg_class'::regclass
|
AND objid = rel_oid
|
AND objsubid = 1
|
AND refclassid = 'pg_catalog.pg_type'::regclass;
|
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_depend rowcount for tmc_ddl_type before ALTER TYPE: got %, expected 0',
|
rowcount;
|
END IF;
|
END;
|
$$;
|
|
SET enable_temp_memory_catalog = off;
|
|
ALTER TABLE pg_temp.tmc_ddl_type
|
ALTER COLUMN a TYPE bigint;
|
|
SELECT pg_typeof(a)::text AS a_type, a, b
|
FROM pg_temp.tmc_ddl_type;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
attr_rowcount bigint;
|
dep_rowcount bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_ddl_type');
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_ddl_type is missing after ALTER TYPE';
|
END IF;
|
|
SELECT count(*) INTO attr_rowcount
|
FROM pg_catalog.pg_attribute
|
WHERE attrelid = rel_oid
|
AND attnum > 0
|
AND NOT attisdropped;
|
|
IF attr_rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_attribute rowcount for tmc_ddl_type after ALTER TYPE: got %, expected 0',
|
attr_rowcount;
|
END IF;
|
|
SELECT count(*) INTO dep_rowcount
|
FROM pg_catalog.pg_depend
|
WHERE classid = 'pg_catalog.pg_class'::regclass
|
AND objid = rel_oid
|
AND objsubid = 1
|
AND refclassid = 'pg_catalog.pg_type'::regclass;
|
|
IF dep_rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_depend rowcount for tmc_ddl_type after ALTER TYPE: got %, expected 0',
|
dep_rowcount;
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.tmc_ddl_type;
|
|
SELECT to_regclass('pg_temp.tmc_ddl_type') IS NULL AS dropped_type_table_missing;
|
|
CREATE DOMAIN public.tmc_ddl_dep_domain AS integer;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_ddl_dep(
|
a integer,
|
keep integer
|
);
|
|
INSERT INTO pg_temp.tmc_ddl_dep
|
VALUES (41, 42);
|
|
SET enable_temp_memory_catalog = off;
|
|
ALTER TABLE pg_temp.tmc_ddl_dep
|
ALTER COLUMN a TYPE public.tmc_ddl_dep_domain;
|
|
SELECT
|
pg_typeof(a) = 'public.tmc_ddl_dep_domain'::regtype AS type_is_domain,
|
a,
|
keep
|
FROM pg_temp.tmc_ddl_dep;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
type_oid oid;
|
rowcount bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_ddl_dep');
|
type_oid := 'public.tmc_ddl_dep_domain'::regtype;
|
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_ddl_dep is missing after ALTER TYPE';
|
END IF;
|
|
SELECT count(*) INTO rowcount
|
FROM pg_catalog.pg_depend
|
WHERE classid = 'pg_catalog.pg_class'::regclass
|
AND objid = rel_oid
|
AND objsubid = 1
|
AND refclassid = 'pg_catalog.pg_type'::regclass
|
AND refobjid = type_oid;
|
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_depend rowcount for tmc_ddl_dep after ALTER TYPE: got %, expected 0',
|
rowcount;
|
END IF;
|
END;
|
$$;
|
|
DO $$
|
DECLARE
|
dependency_blocked boolean := false;
|
BEGIN
|
BEGIN
|
EXECUTE 'DROP DOMAIN public.tmc_ddl_dep_domain RESTRICT';
|
EXCEPTION
|
WHEN SQLSTATE '2BP01' THEN
|
dependency_blocked := true;
|
END;
|
|
IF NOT dependency_blocked THEN
|
RAISE EXCEPTION 'memory datatype dependency did not block DROP DOMAIN';
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.tmc_ddl_dep;
|
|
DROP DOMAIN public.tmc_ddl_dep_domain RESTRICT;
|
|
CREATE DOMAIN public.tmc_ddl_dep_domain_rb AS integer;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_ddl_type_rb(
|
a integer,
|
b integer
|
);
|
|
INSERT INTO pg_temp.tmc_ddl_type_rb
|
VALUES (5, 6);
|
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
SAVEPOINT tmc_type_s;
|
|
ALTER TABLE pg_temp.tmc_ddl_type_rb
|
ALTER COLUMN a TYPE bigint;
|
|
SELECT pg_typeof(a)::text AS during_type, a, b
|
FROM pg_temp.tmc_ddl_type_rb;
|
|
ROLLBACK TO SAVEPOINT tmc_type_s;
|
RELEASE SAVEPOINT tmc_type_s;
|
COMMIT;
|
|
SELECT pg_typeof(a)::text AS after_type, a, b
|
FROM pg_temp.tmc_ddl_type_rb;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
rowcount bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_ddl_type_rb');
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_ddl_type_rb is missing after rollback';
|
END IF;
|
|
SELECT count(*) INTO rowcount
|
FROM pg_catalog.pg_depend
|
WHERE classid = 'pg_catalog.pg_class'::regclass
|
AND objid = rel_oid
|
AND objsubid = 1
|
AND refclassid = 'pg_catalog.pg_type'::regclass;
|
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_depend rowcount for tmc_ddl_type_rb after rollback: got %, expected 0',
|
rowcount;
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.tmc_ddl_type_rb;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_ddl_dep_rb(
|
a integer,
|
keep integer
|
);
|
|
INSERT INTO pg_temp.tmc_ddl_dep_rb
|
VALUES (51, 52);
|
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
SAVEPOINT tmc_dep_type_s;
|
|
ALTER TABLE pg_temp.tmc_ddl_dep_rb
|
ALTER COLUMN a TYPE public.tmc_ddl_dep_domain_rb;
|
|
SELECT
|
pg_typeof(a) = 'public.tmc_ddl_dep_domain_rb'::regtype AS during_is_domain,
|
a,
|
keep
|
FROM pg_temp.tmc_ddl_dep_rb;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
type_oid oid;
|
rowcount bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_ddl_dep_rb');
|
type_oid := 'public.tmc_ddl_dep_domain_rb'::regtype;
|
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_ddl_dep_rb is missing before rollback';
|
END IF;
|
|
SELECT count(*) INTO rowcount
|
FROM pg_catalog.pg_depend
|
WHERE classid = 'pg_catalog.pg_class'::regclass
|
AND objid = rel_oid
|
AND objsubid = 1
|
AND refclassid = 'pg_catalog.pg_type'::regclass
|
AND refobjid = type_oid;
|
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_depend rowcount for tmc_ddl_dep_rb before rollback: got %, expected 0',
|
rowcount;
|
END IF;
|
END;
|
$$;
|
|
ROLLBACK TO SAVEPOINT tmc_dep_type_s;
|
RELEASE SAVEPOINT tmc_dep_type_s;
|
COMMIT;
|
|
SELECT
|
pg_typeof(a) = 'integer'::regtype AS type_rolled_back,
|
a,
|
keep
|
FROM pg_temp.tmc_ddl_dep_rb;
|
|
DROP DOMAIN public.tmc_ddl_dep_domain_rb RESTRICT;
|
|
DROP TABLE pg_temp.tmc_ddl_dep_rb;
|
|
RESET enable_temp_memory_catalog;
|