Add a couple function asserts
This commit is contained in:
parent
4861a21e81
commit
4c7d6c4564
@ -43,6 +43,46 @@ $$
|
|||||||
LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
|
LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION @extschema@.__ft_assert_numeric(input_table regclass, colname name)
|
||||||
|
RETURNS VOID
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
PERFORM atttypid FROM pg_catalog.pg_attribute
|
||||||
|
WHERE attrelid = input_table
|
||||||
|
AND attname = colname
|
||||||
|
AND atttypid IN (SELECT oid FROM pg_type
|
||||||
|
WHERE typname IN
|
||||||
|
('smallint', 'integer', 'bigint', 'int2', 'int4', 'int8'));
|
||||||
|
IF NOT FOUND THEN
|
||||||
|
RAISE EXCEPTION 'non integer id_column "%"', id_column;
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$
|
||||||
|
LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION @extschema@.__ft_assert_geometry(input_table regclass, colname name)
|
||||||
|
RETURNS VOID
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
PERFORM atttypid FROM pg_catalog.pg_attribute
|
||||||
|
WHERE attrelid = input_table
|
||||||
|
AND attname = colname
|
||||||
|
AND atttypid = 'geometry'::regtype;
|
||||||
|
IF NOT FOUND THEN
|
||||||
|
RAISE EXCEPTION 'non geometry column "%"', geom_colum;
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$
|
||||||
|
LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- Public functions
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Set up a federated server for later connection of tables/views
|
-- Set up a federated server for later connection of tables/views
|
||||||
--
|
--
|
||||||
@ -83,15 +123,15 @@ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
|
|||||||
-- 'my_remote_table', -- mandatory, table name
|
-- 'my_remote_table', -- mandatory, table name
|
||||||
-- 'id', -- mandatory, name of the id column
|
-- 'id', -- mandatory, name of the id column
|
||||||
-- 'geom', -- optional, name of the geom column, preferably in 4326
|
-- 'geom', -- optional, name of the geom column, preferably in 4326
|
||||||
-- 'webmercator_column_name', -- optional, must be in 3857 if present
|
-- 'webmercator', -- optional, must be in 3857 if present
|
||||||
-- );
|
-- );
|
||||||
CREATE OR REPLACE FUNCTION @extschema@.CDB_SetUp_PG_Federated_Table(
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_SetUp_PG_Federated_Table(
|
||||||
server_alias text,
|
server_alias text,
|
||||||
schema_name name,
|
schema_name name,
|
||||||
table_name name,
|
table_name name,
|
||||||
id_column name,
|
id_column name,
|
||||||
geom_column_name name,
|
geom_column name,
|
||||||
webmercator_column_name name
|
webmercator_column name
|
||||||
)
|
)
|
||||||
RETURNS void
|
RETURNS void
|
||||||
AS $$
|
AS $$
|
||||||
@ -101,18 +141,14 @@ DECLARE
|
|||||||
BEGIN
|
BEGIN
|
||||||
-- Import the foreign table
|
-- Import the foreign table
|
||||||
PERFORM CDB_SetUp_User_PG_FDW_Table(server_alias, schema_name, table_name);
|
PERFORM CDB_SetUp_User_PG_FDW_Table(server_alias, schema_name, table_name);
|
||||||
|
src_table := format('%s.%s', fdw_objects_name, table_name);
|
||||||
|
|
||||||
-- Check id_column is numeric
|
-- Check id_column is numeric
|
||||||
src_table := format('%s.%s', fdw_objects_name, table_name);
|
PERFORM @extschema@.__ft_assert_numeric(src_table, id_column);
|
||||||
PERFORM atttypid FROM pg_catalog.pg_attribute
|
|
||||||
WHERE attrelid = src_table
|
-- Check if the geom and mercator columns have a geometry type
|
||||||
AND attname = id_column
|
PERFORM @extschema@.__ft_assert_geometry(src_table, geom_column);
|
||||||
AND atttypid IN (SELECT oid FROM pg_type
|
PERFORM @extschema@.__ft_assert_geometry(src_table, webmercator_column);
|
||||||
WHERE typname IN
|
|
||||||
('smallint', 'integer', 'bigint', 'int2', 'int4', 'int8'));
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
RAISE EXCEPTION 'non integer id_column "%"', id_column;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Create the view
|
-- Create the view
|
||||||
EXECUTE format(
|
EXECUTE format(
|
||||||
|
Loading…
Reference in New Issue
Block a user