1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Support more object types within CREATE SCHEMA.

Having rejected the principle that we should know how to re-order
the sub-commands of CREATE SCHEMA, there is not really anything
except a little coding to stop us from supporting more object types.
This patch adds support for creating functions (including procedures
and aggregates), operators, types (including domains), collations,
and text search objects.

SQL:2021 specifies that we should allow functions, procedures,
types, domains, and collations, so this moves us a great deal
closer to full SQL compatibility of CREATE SCHEMA.  What remains
missing from their list are casts, transforms, roles, and some
object types we don't support yet (e.g. CREATE CHARACTER SET).
Supporting casts or transforms would be problematic because
they don't have names at all, let alone schema-qualified names,
so it'd be quite a stretch to say that they belong to a schema.
Roles likewise are not schema-qualified, plus they are global
to a cluster, making it even less reasonable to consider them
as belonging to a schema.  So I don't see us trying to complete
the list.

User-defined aggregates and operators are outside the spec's ken,
as are text search objects, so adding them does not do anything for
spec compatibility.  But they go along with these other object types,
plus it takes no additional code to support them since they are
represented as DefineStmts like some variants of CREATE TYPE.
It would indeed take some effort to reject them.

Author: Kirill Reshke <reshkekirill@gmail.com>
Author: Jian He <jian.universality@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CALdSSPh4jUSDsWu3K58hjO60wnTRR0DuO4CKRcwa8EVuOSfXxg@mail.gmail.com
This commit is contained in:
Tom Lane
2026-04-06 15:16:21 -04:00
parent 404db8f9ed
commit d516974840
9 changed files with 408 additions and 26 deletions

View File

@@ -8,7 +8,7 @@ CREATE ROLE regress_create_schema_role SUPERUSER;
-- Cases where schema creation fails as objects are qualified with a schema
-- that does not match with what's expected.
-- This checks all the object types that include schema qualifications.
-- This checks most object types that include schema qualifications.
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
CREATE SEQUENCE schema_not_existing.seq;
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
@@ -20,6 +20,9 @@ CREATE SCHEMA AUTHORIZATION regress_create_schema_role
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_existing.tab
EXECUTE FUNCTION schema_trig.no_func();
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
CREATE FUNCTION schema_not_existing.func(int) RETURNS int
AS 'SELECT $1' LANGUAGE sql;
-- Again, with a role specification and no schema names.
SET ROLE regress_create_schema_role;
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
@@ -98,5 +101,76 @@ CREATE SCHEMA regress_schema_fk
DROP SCHEMA regress_schema_fk CASCADE;
-- Test miscellaneous object types within CREATE SCHEMA.
CREATE SCHEMA regress_schema_misc
CREATE AGGREGATE cs_sum(int4)
(
SFUNC = int4_sum(int8, int4),
STYPE = int8,
INITCOND = '0'
)
CREATE COLLATION cs_builtin_c ( PROVIDER = builtin, LOCALE = "C" )
CREATE DOMAIN cs_positive AS integer CHECK (VALUE > 0)
CREATE FUNCTION cs_add(int4, int4) returns int4 language sql
as 'select $1 + $2'
CREATE OPERATOR + (function = cs_add, leftarg = int4, rightarg = int4)
CREATE PROCEDURE cs_proc(int4, int4)
BEGIN ATOMIC SELECT cs_add($1,$2); END
CREATE TEXT SEARCH CONFIGURATION cs_ts_conf (copy=english)
CREATE TEXT SEARCH DICTIONARY cs_ts_dict (template=simple)
CREATE TEXT SEARCH PARSER cs_ts_prs
(start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end,
lextypes = prsd_lextype)
CREATE TEXT SEARCH TEMPLATE cs_ts_temp (lexize=dsimple_lexize)
CREATE TYPE regress_schema_misc.cs_enum AS ENUM ('red', 'orange')
CREATE TYPE cs_composite AS (a int, b float8)
CREATE TYPE cs_range AS RANGE (subtype = float8, subtype_diff = float8mi)
-- demonstrate creation of a base type with its I/O functions
CREATE TYPE cs_type
CREATE FUNCTION cs_type_in(cstring)
RETURNS cs_type LANGUAGE internal IMMUTABLE PARALLEL SAFE STRICT
AS 'int4in'
CREATE FUNCTION cs_type_out(cs_type)
RETURNS cstring LANGUAGE internal IMMUTABLE PARALLEL SAFE STRICT
AS 'int4out'
CREATE TYPE cs_type (
INPUT = cs_type_in,
OUTPUT = cs_type_out,
LIKE = int4
)
GRANT USAGE ON TYPE cs_type TO public
;
\df regress_schema_misc.cs_add
\df regress_schema_misc.cs_proc
\da regress_schema_misc.cs_sum
\do regress_schema_misc.+
\dO regress_schema_misc.*
\dT regress_schema_misc.*
\dF regress_schema_misc.*
\dFd regress_schema_misc.*
\dFp regress_schema_misc.*
\dFt regress_schema_misc.*
DROP SCHEMA regress_schema_misc CASCADE;
-- Clean up
DROP ROLE regress_create_schema_role;