Merge pull request #238 from CartoDB/235-column-names
Optimize column information functions
This commit is contained in:
commit
18267477da
@ -2,15 +2,13 @@
|
|||||||
CREATE OR REPLACE FUNCTION CDB_ColumnNames(REGCLASS)
|
CREATE OR REPLACE FUNCTION CDB_ColumnNames(REGCLASS)
|
||||||
RETURNS SETOF information_schema.sql_identifier
|
RETURNS SETOF information_schema.sql_identifier
|
||||||
AS $$
|
AS $$
|
||||||
|
SELECT
|
||||||
SELECT c.column_name
|
a.attname::information_schema.sql_identifier column_name
|
||||||
FROM information_schema.columns c, pg_class _tn, pg_namespace _sn
|
FROM pg_class c
|
||||||
WHERE table_name = _tn.relname
|
LEFT JOIN pg_attribute a ON a.attrelid = c.oid
|
||||||
AND table_schema = _sn.nspname
|
WHERE c.oid = $1::oid
|
||||||
AND _tn.oid = $1::oid
|
AND a.attstattarget < 0 -- exclude system columns
|
||||||
AND _sn.oid = _tn.relnamespace
|
ORDER BY a.attnum;
|
||||||
ORDER BY ordinal_position;
|
|
||||||
|
|
||||||
$$ LANGUAGE SQL;
|
$$ LANGUAGE SQL;
|
||||||
|
|
||||||
-- This is to migrate from pre-0.2.0 version
|
-- This is to migrate from pre-0.2.0 version
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
CREATE OR REPLACE FUNCTION CDB_ColumnType(REGCLASS, TEXT)
|
CREATE OR REPLACE FUNCTION CDB_ColumnType(REGCLASS, TEXT)
|
||||||
RETURNS information_schema.character_data
|
RETURNS information_schema.character_data
|
||||||
AS $$
|
AS $$
|
||||||
|
SELECT
|
||||||
SELECT c.data_type
|
format_type(a.atttypid, NULL)::information_schema.character_data data_type
|
||||||
FROM information_schema.columns c, pg_class _tn, pg_namespace _sn
|
FROM pg_class c
|
||||||
WHERE table_name = _tn.relname
|
LEFT JOIN pg_attribute a ON a.attrelid = c.oid
|
||||||
AND table_schema = _sn.nspname
|
WHERE c.oid = $1::oid
|
||||||
AND column_name = $2
|
AND a.attname = $2
|
||||||
AND _tn.oid = $1::oid
|
AND a.attstattarget < 0; -- exclude system columns
|
||||||
AND _sn.oid = _tn.relnamespace;
|
|
||||||
|
|
||||||
$$ LANGUAGE SQL;
|
$$ LANGUAGE SQL;
|
||||||
|
|
||||||
-- This is to migrate from pre-0.2.0 version
|
-- This is to migrate from pre-0.2.0 version
|
||||||
|
@ -520,15 +520,14 @@ CREATE OR REPLACE FUNCTION _cdb_unlimited_text_column(reloid REGCLASS, col_name
|
|||||||
RETURNS BOOLEAN
|
RETURNS BOOLEAN
|
||||||
AS $$
|
AS $$
|
||||||
SELECT EXISTS (
|
SELECT EXISTS (
|
||||||
SELECT *
|
SELECT a.attname
|
||||||
FROM information_schema.columns c, pg_class _tn, pg_namespace _sn
|
FROM pg_class c
|
||||||
WHERE table_name = _tn.relname
|
LEFT JOIN pg_attribute a ON a.attrelid = c.oid
|
||||||
AND table_schema = _sn.nspname
|
LEFT JOIN pg_type t ON t.oid = a.atttypid
|
||||||
AND c.column_name = col_name
|
WHERE c.oid = reloid
|
||||||
AND _tn.oid = reloid
|
AND a.attname = col_name
|
||||||
AND _sn.oid = _tn.relnamespace
|
AND format_type(a.atttypid, NULL) IN ('text', 'character varying', 'character')
|
||||||
AND character_maximum_length IS NULL
|
AND format_type(a.atttypid, NULL) = format_type(a.atttypid, a.atttypmod)
|
||||||
AND c.data_type IN ('text', 'character varying', 'character')
|
|
||||||
);
|
);
|
||||||
$$ LANGUAGE SQL STABLE;
|
$$ LANGUAGE SQL STABLE;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user