-- The extension is not relocatable: it registers extract(text, jdate) and, for -- jtimestamp and jtimestamptz, extract(), timezone() and overlaps() in pg_catalog -- (EXTRACT, AT TIME ZONE and OVERLAPS always resolve to pg_catalog functions), and -- those functions cannot follow the rest of the extension into another schema, -- so ALTER EXTENSION ... SET SCHEMA cannot work. The schema is chosen at -- install time with CREATE EXTENSION jdate SCHEMA s. -- -- This file drops and recreates the extension, so it must stay LAST in REGRESS. -- The control file says not relocatable (io.sql created it in the default schema) SELECT extname, extrelocatable FROM pg_extension WHERE extname = 'jdate'; extname | extrelocatable ---------+---------------- jdate | f (1 row) -- Install into a dedicated schema CREATE SCHEMA jdate_s; DROP EXTENSION jdate; CREATE EXTENSION jdate SCHEMA jdate_s; SELECT extname, extnamespace::regnamespace AS schema, extrelocatable FROM pg_extension WHERE extname = 'jdate'; extname | schema | extrelocatable ---------+---------+---------------- jdate | jdate_s | f (1 row) -- Every schema-qualified object of the extension lives in jdate_s, except -- pg_catalog.extract(text, jdate), the two pg_catalog.extract() functions and the -- six pg_catalog.timezone() and overlaps() functions of jtimestamp and jtimestamptz. -- (Casts have no schema and are skipped.) SELECT i.type, i.schema, i.identity FROM pg_depend d, LATERAL pg_identify_object(d.classid, d.objid, d.objsubid) i WHERE d.refclassid = 'pg_extension'::regclass AND d.refobjid = (SELECT oid FROM pg_extension WHERE extname = 'jdate') AND d.deptype = 'e' AND i.schema IS NOT NULL AND i.schema <> 'jdate_s' ORDER BY i.type COLLATE "C", i.schema COLLATE "C", i.identity COLLATE "C"; type | schema | identity ----------+------------+------------------------------------------------------------------------------------------------------------ function | pg_catalog | pg_catalog."extract"(pg_catalog.text,jdate_s.jdate) function | pg_catalog | pg_catalog."extract"(pg_catalog.text,jdate_s.jtimestamp) function | pg_catalog | pg_catalog."extract"(pg_catalog.text,jdate_s.jtimestamptz) function | pg_catalog | pg_catalog."overlaps"(jdate_s.jtimestamp,jdate_s.jtimestamp,jdate_s.jtimestamp,jdate_s.jtimestamp) function | pg_catalog | pg_catalog."overlaps"(jdate_s.jtimestamptz,jdate_s.jtimestamptz,jdate_s.jtimestamptz,jdate_s.jtimestamptz) function | pg_catalog | pg_catalog.timezone(interval,jdate_s.jtimestamp) function | pg_catalog | pg_catalog.timezone(interval,jdate_s.jtimestamptz) function | pg_catalog | pg_catalog.timezone(pg_catalog.text,jdate_s.jtimestamp) function | pg_catalog | pg_catalog.timezone(pg_catalog.text,jdate_s.jtimestamptz) (9 rows) -- ... and the kinds of object we expect really are there SELECT DISTINCT i.type COLLATE "C" AS type FROM pg_depend d, LATERAL pg_identify_object(d.classid, d.objid, d.objsubid) i WHERE d.refclassid = 'pg_extension'::regclass AND d.refobjid = (SELECT oid FROM pg_extension WHERE extname = 'jdate') AND d.deptype = 'e' AND i.schema = 'jdate_s' ORDER BY 1; type ----------------- aggregate function operator operator class operator family type (6 rows) -- The type and its array type are in jdate_s and nowhere else SELECT typname, typnamespace::regnamespace AS schema FROM pg_type WHERE typname IN ('jdate', '_jdate') ORDER BY 1, 2; typname | schema ---------+--------- _jdate | jdate_s jdate | jdate_s (2 rows) -- The range and multirange types of jdate, jtimestamp and jtimestamptz and their -- arrays are in jdate_s too, and so are their constructors and support functions SELECT typname, typtype, typnamespace::regnamespace AS schema FROM pg_type WHERE typname ~ '^_?j(date|ts|tstz)(multi)?range$' ORDER BY typname COLLATE "C"; typname | typtype | schema ------------------+---------+--------- _jdatemultirange | b | jdate_s _jdaterange | b | jdate_s _jtsmultirange | b | jdate_s _jtsrange | b | jdate_s _jtstzmultirange | b | jdate_s _jtstzrange | b | jdate_s jdatemultirange | m | jdate_s jdaterange | r | jdate_s jtsmultirange | m | jdate_s jtsrange | r | jdate_s jtstzmultirange | m | jdate_s jtstzrange | r | jdate_s (12 rows) SELECT count(*) FILTER (WHERE pronamespace = 'jdate_s'::regnamespace) AS range_functions_in_jdate_s, count(*) FILTER (WHERE pronamespace <> 'jdate_s'::regnamespace) AS range_functions_elsewhere FROM pg_proc WHERE proname ~ '^j(date|ts|tstz)(multi)?range'; range_functions_in_jdate_s | range_functions_elsewhere ----------------------------+--------------------------- 19 | 0 (1 row) -- jdate_s is not on the search_path, so the type is not visible unqualified... \set VERBOSITY sqlstate SELECT jdate '1403-05-15'; ERROR: 42704 \set VERBOSITY default -- ... the range types work when qualified, and so does the canonical edge check SELECT '[1403-01-01,1403-01-31]'::jdate_s.jdaterange AS range_in_jdate_s; range_in_jdate_s ------------------------- [1403-01-01,1403-02-01) (1 row) SELECT '{[1403-01-01 00:00:00,1403-01-02 00:00:00)}'::jdate_s.jtsmultirange AS multirange_in_jdate_s; multirange_in_jdate_s ------------------------------------------------- {["1403-01-01 00:00:00","1403-01-02 00:00:00")} (1 row) \set VERBOSITY sqlstate SELECT '[1403-01-01,3177-12-29]'::jdate_s.jdaterange; ERROR: 22008 \set VERBOSITY default -- ... but EXTRACT still works, because extract() lives in pg_catalog SELECT EXTRACT(year FROM jdate_s.jdate '1403-05-15') AS year; year ------ 1403 (1 row) SELECT EXTRACT(month FROM jdate_s.jdate '1403-05-15') AS month; month ------- 5 (1 row) SELECT EXTRACT(day FROM jdate_s.jdate '1403-05-15') AS day; day ----- 15 (1 row) SELECT jdate_s.jdate_part('year', jdate_s.jdate '1403-05-15') AS part_year; part_year ----------- 1403 (1 row) -- ALTER EXTENSION ... SET SCHEMA is refused (0A000, feature not supported) \set VERBOSITY sqlstate ALTER EXTENSION jdate SET SCHEMA public; ERROR: 0A000 \set VERBOSITY default -- Same statement again, to show the message (and that there is no DETAIL) ALTER EXTENSION jdate SET SCHEMA public; ERROR: extension "jdate" does not support SET SCHEMA -- The extension is intact: same schema, extract(), timezone() and overlaps() still in pg_catalog SELECT extname, extnamespace::regnamespace AS schema, extrelocatable FROM pg_extension WHERE extname = 'jdate'; extname | schema | extrelocatable ---------+---------+---------------- jdate | jdate_s | f (1 row) SELECT count(*) AS extract_in_pg_catalog FROM pg_proc WHERE proname = 'extract' AND pronamespace = 'pg_catalog'::regnamespace AND pg_get_function_identity_arguments(oid) ~ 'jdate$'; extract_in_pg_catalog ----------------------- 1 (1 row) SELECT count(*) AS timezone_and_overlaps_in_pg_catalog FROM pg_proc WHERE proname IN ('timezone', 'overlaps') AND pronamespace = 'pg_catalog'::regnamespace AND pg_get_function_identity_arguments(oid) ~ 'jtimestamp'; timezone_and_overlaps_in_pg_catalog ------------------------------------- 6 (1 row) SELECT count(*) AS extract_of_timestamps_in_pg_catalog FROM pg_proc WHERE proname = 'extract' AND pronamespace = 'pg_catalog'::regnamespace AND pg_get_function_identity_arguments(oid) ~ 'jtimestamp'; extract_of_timestamps_in_pg_catalog ------------------------------------- 2 (1 row) SELECT count(*) AS extension_functions_outside_jdate_s FROM pg_depend d WHERE d.classid = 'pg_proc'::regclass AND d.refclassid = 'pg_extension'::regclass AND d.refobjid = (SELECT oid FROM pg_extension WHERE extname = 'jdate') AND d.deptype = 'e' AND (SELECT pronamespace FROM pg_proc WHERE oid = d.objid) <> 'jdate_s'::regnamespace; extension_functions_outside_jdate_s ------------------------------------- 9 (1 row) SELECT EXTRACT(year FROM jdate_s.jdate '1403-05-15') AS year_after_failed_alter; year_after_failed_alter ------------------------- 1403 (1 row) -- DROP EXTENSION removes pg_catalog.extract(), timezone() and overlaps() of our types, and the types DROP EXTENSION jdate; SELECT count(*) AS extract_in_pg_catalog FROM pg_proc WHERE proname = 'extract' AND pronamespace = 'pg_catalog'::regnamespace AND pg_get_function_identity_arguments(oid) ~ 'jdate$'; extract_in_pg_catalog ----------------------- 0 (1 row) SELECT count(*) AS timezone_and_overlaps_in_pg_catalog FROM pg_proc WHERE proname IN ('timezone', 'overlaps') AND pronamespace = 'pg_catalog'::regnamespace AND pg_get_function_identity_arguments(oid) ~ 'jtimestamp'; timezone_and_overlaps_in_pg_catalog ------------------------------------- 0 (1 row) SELECT count(*) AS extract_of_timestamps_in_pg_catalog FROM pg_proc WHERE proname = 'extract' AND pronamespace = 'pg_catalog'::regnamespace AND pg_get_function_identity_arguments(oid) ~ 'jtimestamp'; extract_of_timestamps_in_pg_catalog ------------------------------------- 0 (1 row) SELECT count(*) AS jdate_types FROM pg_type WHERE typname IN ('jdate', '_jdate'); jdate_types ------------- 0 (1 row) SELECT count(*) AS range_types FROM pg_type WHERE typname ~ '^_?j(date|ts|tstz)(multi)?range$'; range_types ------------- 0 (1 row) SELECT count(*) AS objects_left_in_jdate_s FROM pg_depend WHERE refclassid = 'pg_namespace'::regclass AND refobjid = 'jdate_s'::regnamespace; objects_left_in_jdate_s ------------------------- 0 (1 row) -- Back to the default schema, as the other tests expect DROP SCHEMA jdate_s; CREATE EXTENSION jdate; SELECT extname, extnamespace::regnamespace AS schema, extrelocatable FROM pg_extension WHERE extname = 'jdate'; extname | schema | extrelocatable ---------+--------+---------------- jdate | public | f (1 row) SELECT EXTRACT(year FROM jdate '1403-05-15') AS year; year ------ 1403 (1 row)