2016-05-21 05:34:05 -05:00
|
|
|
{# SQL query for getting columns #}
|
|
|
|
{% if object_name == 'table' %}
|
2018-08-27 04:30:56 -05:00
|
|
|
SELECT nsp.nspname schema_name,
|
|
|
|
cls.relname table_name,
|
|
|
|
att.attname column_name,
|
|
|
|
att.atttypid::regtype::text type_name,
|
|
|
|
att.atthasdef AS has_default,
|
2019-06-10 08:24:45 -05:00
|
|
|
pg_get_expr(def.adbin, def.adrelid) as default
|
2018-08-27 04:30:56 -05:00
|
|
|
FROM pg_catalog.pg_attribute att
|
|
|
|
INNER JOIN pg_catalog.pg_class cls
|
|
|
|
ON att.attrelid = cls.oid
|
|
|
|
INNER JOIN pg_catalog.pg_namespace nsp
|
|
|
|
ON cls.relnamespace = nsp.oid
|
2021-03-11 23:47:25 -06:00
|
|
|
LEFT OUTER JOIN pg_catalog.pg_attrdef def
|
2018-08-27 04:30:56 -05:00
|
|
|
ON def.adrelid = att.attrelid
|
|
|
|
AND def.adnum = att.attnum
|
|
|
|
WHERE nsp.nspname IN ({{schema_names}})
|
2022-03-07 02:36:40 -06:00
|
|
|
AND cls.relkind = ANY(array['r', 'p'])
|
2016-05-21 05:34:05 -05:00
|
|
|
AND NOT att.attisdropped
|
|
|
|
AND att.attnum > 0
|
2018-08-27 04:30:56 -05:00
|
|
|
ORDER BY 1, 2, att.attnum
|
2016-05-21 05:34:05 -05:00
|
|
|
{% endif %}
|
|
|
|
{% if object_name == 'view' %}
|
2018-08-27 04:30:56 -05:00
|
|
|
SELECT nsp.nspname schema_name,
|
|
|
|
cls.relname table_name,
|
|
|
|
att.attname column_name,
|
|
|
|
att.atttypid::regtype::text type_name,
|
|
|
|
att.atthasdef AS has_default,
|
2019-06-10 08:24:45 -05:00
|
|
|
pg_get_expr(def.adbin, def.adrelid) as default
|
2018-08-27 04:30:56 -05:00
|
|
|
FROM pg_catalog.pg_attribute att
|
|
|
|
INNER JOIN pg_catalog.pg_class cls
|
|
|
|
ON att.attrelid = cls.oid
|
|
|
|
INNER JOIN pg_catalog.pg_namespace nsp
|
|
|
|
ON cls.relnamespace = nsp.oid
|
2021-03-11 23:47:25 -06:00
|
|
|
LEFT OUTER JOIN pg_catalog.pg_attrdef def
|
2018-08-27 04:30:56 -05:00
|
|
|
ON def.adrelid = att.attrelid
|
|
|
|
AND def.adnum = att.attnum
|
|
|
|
WHERE nsp.nspname IN ({{schema_names}})
|
|
|
|
AND cls.relkind = ANY(array['v', 'm'])
|
2016-05-21 05:34:05 -05:00
|
|
|
AND NOT att.attisdropped
|
|
|
|
AND att.attnum > 0
|
2018-08-27 04:30:56 -05:00
|
|
|
ORDER BY 1, 2, att.attnum
|
|
|
|
{% endif %}
|