"\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)"
"\n FROM pg_catalog.pg_attrdef d"
"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),"
- "\n a.attnotnull, a.attnum");
+ "\n a.attnotnull, a.attnum,");
if (pset.sversion >= 90100)
- appendPQExpBuffer(&buf, ",\n (SELECT collname FROM pg_collation WHERE oid = a.attcollation AND collname <> 'default') AS attcollation");
+ appendPQExpBuffer(&buf, "\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n"
+ " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
else
- appendPQExpBuffer(&buf, ",\n NULL AS attcollation");
+ appendPQExpBuffer(&buf, "\n NULL AS attcollation");
if (tableinfo.relkind == 'i')
appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
if (verbose)
cols = 2;
if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
- tableinfo.relkind == 'f')
+ tableinfo.relkind == 'f' || tableinfo.relkind == 'c')
{
show_modifiers = true;
headers[cols++] = gettext_noop("Modifiers");
printfPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n"
" t.typname as \"%s\",\n"
- " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
- " CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
- " WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
- " WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
- " ELSE ''\n"
- " END as \"%s\",\n"
+ " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
+ " TRIM(LEADING\n",
+ gettext_noop("Schema"),
+ gettext_noop("Name"),
+ gettext_noop("Type"));
+ if (pset.sversion >= 90100)
+ appendPQExpBuffer(&buf,
+ " COALESCE((SELECT ' collate ' || c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
+ " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation), '') ||\n");
+ appendPQExpBuffer(&buf,
+ " CASE WHEN t.typnotnull THEN ' not null' ELSE '' END ||\n"
+ " CASE WHEN t.typdefault IS NOT NULL THEN ' default ' || t.typdefault ELSE '' END\n"
+ " ) as \"%s\",\n",
+ gettext_noop("Modifier"));
+ appendPQExpBuffer(&buf,
" pg_catalog.array_to_string(ARRAY(\n"
" SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
" ), ' ') as \"%s\"\n"
"FROM pg_catalog.pg_type t\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
"WHERE t.typtype = 'd'\n",
- gettext_noop("Schema"),
- gettext_noop("Name"),
- gettext_noop("Type"),
- gettext_noop("Modifier"),
gettext_noop("Check"));
if (!showSystem && !pattern)
CREATE TYPE test_type AS (a int);
\d test_type
Composite type "public.test_type"
- Column | Type
---------+---------
- a | integer
+ Column | Type | Modifiers
+--------+---------+-----------
+ a | integer |
ALTER TYPE nosuchtype ADD ATTRIBUTE b text; -- fails
ERROR: relation "nosuchtype" does not exist
ALTER TYPE test_type ADD ATTRIBUTE b text;
\d test_type
Composite type "public.test_type"
- Column | Type
---------+---------
- a | integer
- b | text
+ Column | Type | Modifiers
+--------+---------+-----------
+ a | integer |
+ b | text |
ALTER TYPE test_type ADD ATTRIBUTE b text; -- fails
ERROR: column "b" of relation "test_type" already exists
ALTER TYPE test_type ALTER ATTRIBUTE b SET DATA TYPE varchar;
\d test_type
-Composite type "public.test_type"
- Column | Type
---------+-------------------
- a | integer
- b | character varying
+ Composite type "public.test_type"
+ Column | Type | Modifiers
+--------+-------------------+-----------
+ a | integer |
+ b | character varying |
ALTER TYPE test_type ALTER ATTRIBUTE b SET DATA TYPE integer;
\d test_type
Composite type "public.test_type"
- Column | Type
---------+---------
- a | integer
- b | integer
+ Column | Type | Modifiers
+--------+---------+-----------
+ a | integer |
+ b | integer |
ALTER TYPE test_type DROP ATTRIBUTE b;
\d test_type
Composite type "public.test_type"
- Column | Type
---------+---------
- a | integer
+ Column | Type | Modifiers
+--------+---------+-----------
+ a | integer |
ALTER TYPE test_type DROP ATTRIBUTE c; -- fails
ERROR: column "c" of relation "test_type" does not exist
ALTER TYPE test_type DROP ATTRIBUTE a, ADD ATTRIBUTE d boolean;
\d test_type
Composite type "public.test_type"
- Column | Type
---------+---------
- d | boolean
+ Column | Type | Modifiers
+--------+---------+-----------
+ d | boolean |
ALTER TYPE test_type RENAME ATTRIBUTE a TO aa;
ERROR: column "a" does not exist
ALTER TYPE test_type RENAME ATTRIBUTE d TO dd;
\d test_type
Composite type "public.test_type"
- Column | Type
---------+---------
- dd | boolean
+ Column | Type | Modifiers
+--------+---------+-----------
+ dd | boolean |
DROP TYPE test_type;
CREATE TYPE test_type1 AS (a int, b text);
CREATE TABLE test_tbl2 OF test_type2;
\d test_type2
Composite type "public.test_type2"
- Column | Type
---------+---------
- a | integer
- b | text
+ Column | Type | Modifiers
+--------+---------+-----------
+ a | integer |
+ b | text |
\d test_tbl2
Table "public.test_tbl2"
ALTER TYPE test_type2 ADD ATTRIBUTE c text CASCADE;
\d test_type2
Composite type "public.test_type2"
- Column | Type
---------+---------
- a | integer
- b | text
- c | text
+ Column | Type | Modifiers
+--------+---------+-----------
+ a | integer |
+ b | text |
+ c | text |
\d test_tbl2
Table "public.test_tbl2"
HINT: Use ALTER ... CASCADE to alter the typed tables too.
ALTER TYPE test_type2 ALTER ATTRIBUTE b TYPE varchar CASCADE;
\d test_type2
-Composite type "public.test_type2"
- Column | Type
---------+-------------------
- a | integer
- b | character varying
- c | text
+ Composite type "public.test_type2"
+ Column | Type | Modifiers
+--------+-------------------+-----------
+ a | integer |
+ b | character varying |
+ c | text |
\d test_tbl2
Table "public.test_tbl2"
ALTER TYPE test_type2 DROP ATTRIBUTE b CASCADE;
\d test_type2
Composite type "public.test_type2"
- Column | Type
---------+---------
- a | integer
- c | text
+ Column | Type | Modifiers
+--------+---------+-----------
+ a | integer |
+ c | text |
\d test_tbl2
Table "public.test_tbl2"
ALTER TYPE test_type2 RENAME ATTRIBUTE a TO aa CASCADE;
\d test_type2
Composite type "public.test_type2"
- Column | Type
---------+---------
- aa | integer
- c | text
+ Column | Type | Modifiers
+--------+---------+-----------
+ aa | integer |
+ c | text |
\d test_tbl2
Table "public.test_tbl2"