Add views to replace psql's \d as needed

pull/1439/head
Jason Petersen 2017-05-30 17:02:40 -06:00
parent 38f25020e3
commit 60d15367ca
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
2 changed files with 242 additions and 0 deletions

View File

@ -197,3 +197,117 @@ ALTER EXTENSION citus UPDATE;
--------+------+------+-------
(0 rows)
\c - - - :master_port
CREATE VIEW table_fkeys AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'f';
-- create views used to describe relations
CREATE VIEW table_attrs AS
SELECT a.attname AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default",
a.attnotnull AS "notnull",
a.attrelid AS "relid"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
CREATE VIEW table_desc AS
SELECT "name" AS "Column",
"type" as "Type",
rtrim((
CASE "notnull"
WHEN true THEN 'not null '
ELSE ''
END
) || (
CASE WHEN "default" IS NULL THEN ''
ELSE 'default ' || "default"
END
)) AS "Modifiers",
"relid"
FROM table_attrs;
CREATE VIEW table_checks AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'c';
\c - - - :worker_1_port
CREATE VIEW table_fkeys AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'f';
-- create views used to describe relations
CREATE VIEW table_attrs AS
SELECT a.attname AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default",
a.attnotnull AS "notnull",
a.attrelid AS "relid"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
CREATE VIEW table_desc AS
SELECT "name" AS "Column",
"type" as "Type",
rtrim((
CASE "notnull"
WHEN true THEN 'not null '
ELSE ''
END
) || (
CASE WHEN "default" IS NULL THEN ''
ELSE 'default ' || "default"
END
)) AS "Modifiers",
"relid"
FROM table_attrs;
CREATE VIEW table_checks AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'c';
\c - - - :worker_2_port
-- create views used to describe relations
CREATE VIEW table_attrs AS
SELECT a.attname AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default",
a.attnotnull AS "notnull",
a.attrelid AS "relid"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
CREATE VIEW table_desc AS
SELECT "name" AS "Column",
"type" as "Type",
rtrim((
CASE "notnull"
WHEN true THEN 'not null '
ELSE ''
END
) || (
CASE WHEN "default" IS NULL THEN ''
ELSE 'default ' || "default"
END
)) AS "Modifiers",
"relid"
FROM table_attrs;
CREATE VIEW table_checks AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'c';

View File

@ -175,3 +175,131 @@ ALTER EXTENSION citus UPDATE;
-- if cache is invalidated succesfull, this \d should work without any problem
\d
\c - - - :master_port
CREATE VIEW table_fkeys AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'f';
-- create views used to describe relations
CREATE VIEW table_attrs AS
SELECT a.attname AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default",
a.attnotnull AS "notnull",
a.attrelid AS "relid"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
CREATE VIEW table_desc AS
SELECT "name" AS "Column",
"type" as "Type",
rtrim((
CASE "notnull"
WHEN true THEN 'not null '
ELSE ''
END
) || (
CASE WHEN "default" IS NULL THEN ''
ELSE 'default ' || "default"
END
)) AS "Modifiers",
"relid"
FROM table_attrs;
CREATE VIEW table_checks AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'c';
\c - - - :worker_1_port
CREATE VIEW table_fkeys AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'f';
-- create views used to describe relations
CREATE VIEW table_attrs AS
SELECT a.attname AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default",
a.attnotnull AS "notnull",
a.attrelid AS "relid"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
CREATE VIEW table_desc AS
SELECT "name" AS "Column",
"type" as "Type",
rtrim((
CASE "notnull"
WHEN true THEN 'not null '
ELSE ''
END
) || (
CASE WHEN "default" IS NULL THEN ''
ELSE 'default ' || "default"
END
)) AS "Modifiers",
"relid"
FROM table_attrs;
CREATE VIEW table_checks AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'c';
\c - - - :worker_2_port
-- create views used to describe relations
CREATE VIEW table_attrs AS
SELECT a.attname AS "name",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "type",
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS "default",
a.attnotnull AS "notnull",
a.attrelid AS "relid"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
CREATE VIEW table_desc AS
SELECT "name" AS "Column",
"type" as "Type",
rtrim((
CASE "notnull"
WHEN true THEN 'not null '
ELSE ''
END
) || (
CASE WHEN "default" IS NULL THEN ''
ELSE 'default ' || "default"
END
)) AS "Modifiers",
"relid"
FROM table_attrs;
CREATE VIEW table_checks AS
SELECT r.conname AS "Constraint",
pg_catalog.pg_get_constraintdef(r.oid, true) AS "Definition",
conrelid AS "relid"
FROM pg_catalog.pg_constraint r
WHERE r.contype = 'c';