$$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL COST 200;
+-- Availability: 2.0.0
+-- TODO: Can't deprecate this because UpdateGeometrySRID still uses them
+CREATE OR REPLACE FUNCTION postgis_constraint_srid(geomschema text, geomtable text, geomcolumn text) RETURNS integer AS
+$$
+SELECT replace(replace(split_part(s.consrc, ' = ', 2), ')', ''), '(', '')::integer
+ FROM pg_class c, pg_namespace n, pg_attribute a
+ , (SELECT connamespace, conrelid, conkey, pg_get_constraintdef(oid) As consrc
+ FROM pg_constraint) AS s
+ WHERE n.nspname = $1
+ AND c.relname = $2
+ AND a.attname = $3
+ AND a.attrelid = c.oid
+ AND s.connamespace = n.oid
+ AND s.conrelid = c.oid
+ AND a.attnum = ANY (s.conkey)
+ AND s.consrc LIKE '%srid(% = %';
+$$
+LANGUAGE 'sql' STABLE STRICT _PARALLEL;
+
+-- Availability: 2.0.0
+-- TODO: Can't deprecate this because UpdateGeometrySRID still uses them
+CREATE OR REPLACE FUNCTION postgis_constraint_dims(geomschema text, geomtable text, geomcolumn text) RETURNS integer AS
+$$
+SELECT replace(split_part(s.consrc, ' = ', 2), ')', '')::integer
+ FROM pg_class c, pg_namespace n, pg_attribute a
+ , (SELECT connamespace, conrelid, conkey, pg_get_constraintdef(oid) As consrc
+ FROM pg_constraint) AS s
+ WHERE n.nspname = $1
+ AND c.relname = $2
+ AND a.attname = $3
+ AND a.attrelid = c.oid
+ AND s.connamespace = n.oid
+ AND s.conrelid = c.oid
+ AND a.attnum = ANY (s.conkey)
+ AND s.consrc LIKE '%ndims(% = %';
+$$
+LANGUAGE 'sql' STABLE STRICT _PARALLEL;
+
+-- support function to pull out geometry type from constraint check
+-- will return pretty name instead of ugly name
+-- Availability: 2.0.0
+-- TODO: Can't deprecate this because UpdateGeometrySRID still uses them
+CREATE OR REPLACE FUNCTION postgis_constraint_type(geomschema text, geomtable text, geomcolumn text) RETURNS varchar AS
+$$
+SELECT replace(split_part(s.consrc, '''', 2), ')', '')::varchar
+ FROM pg_class c, pg_namespace n, pg_attribute a
+ , (SELECT connamespace, conrelid, conkey, pg_get_constraintdef(oid) As consrc
+ FROM pg_constraint) AS s
+ WHERE n.nspname = $1
+ AND c.relname = $2
+ AND a.attname = $3
+ AND a.attrelid = c.oid
+ AND s.connamespace = n.oid
+ AND s.conrelid = c.oid
+ AND a.attnum = ANY (s.conkey)
+ AND s.consrc LIKE '%geometrytype(% = %';
+$$
+LANGUAGE 'sql' STABLE STRICT _PARALLEL;
+
-- Availability: 2.0.0
-- Changed: 2.1.8 significant performance improvement for constraint based columns
-- Changed: 2.2.0 get rid of schema, table, column cast to improve performance
s.conrelid,
s.conkey, replace(split_part(s.consrc, ''''::text, 2), ')'::text, ''::text) As type
FROM (SELECT connamespace, conrelid, conkey, pg_get_constraintdef(oid) As consrc
- FROM pg_constraint) AS s
+ FROM pg_constraint) AS s
WHERE s.consrc ~~* '%geometrytype(% = %'::text
) st ON st.connamespace = n.oid AND st.conrelid = c.oid AND (a.attnum = ANY (st.conkey))
SELECT
TRUE
FROM pg_class c, pg_namespace n, pg_attribute a
- , (SELECT connamespace, conrelid, conkey, contype, pg_get_constraintdef(oid) As consrc
+ , (SELECT connamespace, conrelid, conindid, conkey, contype, conexclop, pg_get_constraintdef(oid) As consrc
FROM pg_constraint) AS s
, pg_index idx, pg_operator op
WHERE n.nspname = $1
SELECT
s.conname INTO cn
FROM pg_class c, pg_namespace n, pg_attribute a
- , (SELECT connamespace, conrelid, conkey, contype, pg_get_constraintdef(oid) As consrc
+ , (SELECT connamespace, conrelid, conkey, conindid, contype, conexclop, pg_get_constraintdef(oid) As consrc
FROM pg_constraint) AS s
, pg_index idx, pg_operator op
WHERE n.nspname = $1