Skip to content

Commit e4fddfd

Browse files
committed
psql: Support identity columns in sequence display
Where the footer for an owned serial sequence would say "Owned by", put something analogous for a sequence belonging to an identity column. Reported-by: Vitaly Burovoy <vitaly.burovoy@gmail.com>
1 parent 5e1ccd4 commit e4fddfd

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/bin/psql/describe.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,8 @@ describeOneTableDetails(const char *schemaname,
20062006
/* Get the column that owns this sequence */
20072007
printfPQExpBuffer(&buf, "SELECT pg_catalog.quote_ident(nspname) || '.' ||"
20082008
"\n pg_catalog.quote_ident(relname) || '.' ||"
2009-
"\n pg_catalog.quote_ident(attname)"
2009+
"\n pg_catalog.quote_ident(attname),"
2010+
"\n d.deptype"
20102011
"\nFROM pg_catalog.pg_class c"
20112012
"\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
20122013
"\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
@@ -2016,17 +2017,27 @@ describeOneTableDetails(const char *schemaname,
20162017
"\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
20172018
"\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
20182019
"\n AND d.objid=%s"
2019-
"\n AND d.deptype='a'",
2020+
"\n AND d.deptype IN ('a', 'i')",
20202021
oid);
20212022

20222023
result = PSQLexec(buf.data);
20232024
if (!result)
20242025
goto error_return;
20252026
else if (PQntuples(result) == 1)
20262027
{
2027-
printfPQExpBuffer(&buf, _("Owned by: %s"),
2028-
PQgetvalue(result, 0, 0));
2029-
printTableAddFooter(&cont, buf.data);
2028+
switch (PQgetvalue(result, 0, 1)[0])
2029+
{
2030+
case 'a':
2031+
printfPQExpBuffer(&buf, _("Owned by: %s"),
2032+
PQgetvalue(result, 0, 0));
2033+
printTableAddFooter(&cont, buf.data);
2034+
break;
2035+
case 'i':
2036+
printfPQExpBuffer(&buf, _("Sequence for identity column: %s"),
2037+
PQgetvalue(result, 0, 0));
2038+
printTableAddFooter(&cont, buf.data);
2039+
break;
2040+
}
20302041
}
20312042

20322043
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy