cartodb-postgresql/scripts-available/CDB_ColumnType.sql

17 lines
645 B
MySQL
Raw Normal View History

-- Function returning the type of a column
2019-05-31 21:29:28 +08:00
CREATE OR REPLACE FUNCTION @extschema@.CDB_ColumnType(REGCLASS, TEXT)
RETURNS information_schema.character_data
AS $$
2016-04-19 01:07:33 +08:00
SELECT
2016-04-25 22:30:58 +08:00
format_type(a.atttypid, NULL)::information_schema.character_data data_type
2016-04-19 01:07:33 +08:00
FROM pg_class c
2016-04-25 22:30:58 +08:00
LEFT JOIN pg_attribute a ON a.attrelid = c.oid
2016-04-19 01:07:33 +08:00
WHERE c.oid = $1::oid
AND a.attname = $2
2016-04-25 22:30:58 +08:00
AND a.attstattarget < 0; -- exclude system columns
2017-10-24 20:16:56 +08:00
$$ LANGUAGE SQL STABLE PARALLEL SAFE;
-- This is to migrate from pre-0.2.0 version
-- See http://github.com/CartoDB/cartodb-postgresql/issues/36
2019-05-31 21:29:28 +08:00
GRANT EXECUTE ON FUNCTION @extschema@.CDB_ColumnType(REGCLASS, TEXT) TO public;