Change table_attrs view to use information_schema

pull/1439/head
Jason Petersen 2017-06-09 14:26:35 -06:00
parent b97b435616
commit 2ca3952b1d
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
2 changed files with 96 additions and 72 deletions

View File

@ -221,20 +221,24 @@ SELECT name AS "Constraint",
FROM table_fkey_cols FROM table_fkey_cols
GROUP BY (name, relid); GROUP BY (name, relid);
-- create views used to describe relations -- create views used to describe relations
CREATE VIEW table_attrs AS CREATE OR REPLACE VIEW table_attrs AS
SELECT a.attname AS "name", SELECT c.column_name AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type", c.data_type AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128) CASE
FROM pg_catalog.pg_attrdef d WHEN character_maximum_length IS NOT NULL THEN
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default", format('(%s)', character_maximum_length)
a.attnotnull AS "notnull", WHEN data_type = 'numeric' AND numeric_precision IS NOT NULL THEN
a.attrelid AS "relid" format('(%s,%s)', numeric_precision, numeric_scale)
FROM pg_catalog.pg_attribute a ELSE ''
WHERE a.attnum > 0 AND NOT a.attisdropped END AS "modifier",
ORDER BY a.attnum; c.column_default AS "default",
(NOT c.is_nullable::boolean) AS "notnull",
format('%I.%I', c.table_schema, c.table_name)::regclass::oid AS "relid"
FROM information_schema.columns AS c
ORDER BY ordinal_position;
CREATE VIEW table_desc AS CREATE VIEW table_desc AS
SELECT "name" AS "Column", SELECT "name" AS "Column",
"type" as "Type", "type" || "modifier" AS "Type",
rtrim(( rtrim((
CASE "notnull" CASE "notnull"
WHEN true THEN 'not null ' WHEN true THEN 'not null '
@ -280,20 +284,24 @@ SELECT name AS "Constraint",
FROM table_fkey_cols FROM table_fkey_cols
GROUP BY (name, relid); GROUP BY (name, relid);
-- create views used to describe relations -- create views used to describe relations
CREATE VIEW table_attrs AS CREATE OR REPLACE VIEW table_attrs AS
SELECT a.attname AS "name", SELECT c.column_name AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type", c.data_type AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128) CASE
FROM pg_catalog.pg_attrdef d WHEN character_maximum_length IS NOT NULL THEN
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default", format('(%s)', character_maximum_length)
a.attnotnull AS "notnull", WHEN data_type = 'numeric' AND numeric_precision IS NOT NULL THEN
a.attrelid AS "relid" format('(%s,%s)', numeric_precision, numeric_scale)
FROM pg_catalog.pg_attribute a ELSE ''
WHERE a.attnum > 0 AND NOT a.attisdropped END AS "modifier",
ORDER BY a.attnum; c.column_default AS "default",
(NOT c.is_nullable::boolean) AS "notnull",
format('%I.%I', c.table_schema, c.table_name)::regclass::oid AS "relid"
FROM information_schema.columns AS c
ORDER BY ordinal_position;
CREATE VIEW table_desc AS CREATE VIEW table_desc AS
SELECT "name" AS "Column", SELECT "name" AS "Column",
"type" as "Type", "type" || "modifier" AS "Type",
rtrim(( rtrim((
CASE "notnull" CASE "notnull"
WHEN true THEN 'not null ' WHEN true THEN 'not null '
@ -317,20 +325,24 @@ WHERE cc.constraint_schema = ccu.constraint_schema AND
ORDER BY cc.constraint_name ASC; ORDER BY cc.constraint_name ASC;
\c - - - :worker_2_port \c - - - :worker_2_port
-- create views used to describe relations -- create views used to describe relations
CREATE VIEW table_attrs AS CREATE OR REPLACE VIEW table_attrs AS
SELECT a.attname AS "name", SELECT c.column_name AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type", c.data_type AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128) CASE
FROM pg_catalog.pg_attrdef d WHEN character_maximum_length IS NOT NULL THEN
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default", format('(%s)', character_maximum_length)
a.attnotnull AS "notnull", WHEN data_type = 'numeric' AND numeric_precision IS NOT NULL THEN
a.attrelid AS "relid" format('(%s,%s)', numeric_precision, numeric_scale)
FROM pg_catalog.pg_attribute a ELSE ''
WHERE a.attnum > 0 AND NOT a.attisdropped END AS "modifier",
ORDER BY a.attnum; c.column_default AS "default",
(NOT c.is_nullable::boolean) AS "notnull",
format('%I.%I', c.table_schema, c.table_name)::regclass::oid AS "relid"
FROM information_schema.columns AS c
ORDER BY ordinal_position;
CREATE VIEW table_desc AS CREATE VIEW table_desc AS
SELECT "name" AS "Column", SELECT "name" AS "Column",
"type" as "Type", "type" || "modifier" AS "Type",
rtrim(( rtrim((
CASE "notnull" CASE "notnull"
WHEN true THEN 'not null ' WHEN true THEN 'not null '

View File

@ -203,21 +203,25 @@ FROM table_fkey_cols
GROUP BY (name, relid); GROUP BY (name, relid);
-- create views used to describe relations -- create views used to describe relations
CREATE VIEW table_attrs AS CREATE OR REPLACE VIEW table_attrs AS
SELECT a.attname AS "name", SELECT c.column_name AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type", c.data_type AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128) CASE
FROM pg_catalog.pg_attrdef d WHEN character_maximum_length IS NOT NULL THEN
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default", format('(%s)', character_maximum_length)
a.attnotnull AS "notnull", WHEN data_type = 'numeric' AND numeric_precision IS NOT NULL THEN
a.attrelid AS "relid" format('(%s,%s)', numeric_precision, numeric_scale)
FROM pg_catalog.pg_attribute a ELSE ''
WHERE a.attnum > 0 AND NOT a.attisdropped END AS "modifier",
ORDER BY a.attnum; c.column_default AS "default",
(NOT c.is_nullable::boolean) AS "notnull",
format('%I.%I', c.table_schema, c.table_name)::regclass::oid AS "relid"
FROM information_schema.columns AS c
ORDER BY ordinal_position;
CREATE VIEW table_desc AS CREATE VIEW table_desc AS
SELECT "name" AS "Column", SELECT "name" AS "Column",
"type" as "Type", "type" || "modifier" AS "Type",
rtrim(( rtrim((
CASE "notnull" CASE "notnull"
WHEN true THEN 'not null ' WHEN true THEN 'not null '
@ -268,21 +272,25 @@ FROM table_fkey_cols
GROUP BY (name, relid); GROUP BY (name, relid);
-- create views used to describe relations -- create views used to describe relations
CREATE VIEW table_attrs AS CREATE OR REPLACE VIEW table_attrs AS
SELECT a.attname AS "name", SELECT c.column_name AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type", c.data_type AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128) CASE
FROM pg_catalog.pg_attrdef d WHEN character_maximum_length IS NOT NULL THEN
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default", format('(%s)', character_maximum_length)
a.attnotnull AS "notnull", WHEN data_type = 'numeric' AND numeric_precision IS NOT NULL THEN
a.attrelid AS "relid" format('(%s,%s)', numeric_precision, numeric_scale)
FROM pg_catalog.pg_attribute a ELSE ''
WHERE a.attnum > 0 AND NOT a.attisdropped END AS "modifier",
ORDER BY a.attnum; c.column_default AS "default",
(NOT c.is_nullable::boolean) AS "notnull",
format('%I.%I', c.table_schema, c.table_name)::regclass::oid AS "relid"
FROM information_schema.columns AS c
ORDER BY ordinal_position;
CREATE VIEW table_desc AS CREATE VIEW table_desc AS
SELECT "name" AS "Column", SELECT "name" AS "Column",
"type" as "Type", "type" || "modifier" AS "Type",
rtrim(( rtrim((
CASE "notnull" CASE "notnull"
WHEN true THEN 'not null ' WHEN true THEN 'not null '
@ -309,21 +317,25 @@ ORDER BY cc.constraint_name ASC;
\c - - - :worker_2_port \c - - - :worker_2_port
-- create views used to describe relations -- create views used to describe relations
CREATE VIEW table_attrs AS CREATE OR REPLACE VIEW table_attrs AS
SELECT a.attname AS "name", SELECT c.column_name AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type", c.data_type AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128) CASE
FROM pg_catalog.pg_attrdef d WHEN character_maximum_length IS NOT NULL THEN
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default", format('(%s)', character_maximum_length)
a.attnotnull AS "notnull", WHEN data_type = 'numeric' AND numeric_precision IS NOT NULL THEN
a.attrelid AS "relid" format('(%s,%s)', numeric_precision, numeric_scale)
FROM pg_catalog.pg_attribute a ELSE ''
WHERE a.attnum > 0 AND NOT a.attisdropped END AS "modifier",
ORDER BY a.attnum; c.column_default AS "default",
(NOT c.is_nullable::boolean) AS "notnull",
format('%I.%I', c.table_schema, c.table_name)::regclass::oid AS "relid"
FROM information_schema.columns AS c
ORDER BY ordinal_position;
CREATE VIEW table_desc AS CREATE VIEW table_desc AS
SELECT "name" AS "Column", SELECT "name" AS "Column",
"type" as "Type", "type" || "modifier" AS "Type",
rtrim(( rtrim((
CASE "notnull" CASE "notnull"
WHEN true THEN 'not null ' WHEN true THEN 'not null '