Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f81a1f

Browse files
committed
Make psql \d on a sequence show the table/column owning it
1 parent039680a commit6f81a1f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎src/bin/psql/describe.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,43 @@ describeOneTableDetails(const char *schemaname,
16091609
PQclear(result);
16101610
}
16111611
}
1612+
elseif (tableinfo.relkind=='S')
1613+
{
1614+
/* Footer information about a sequence */
1615+
PGresult*result=NULL;
1616+
1617+
/* Get the column that owns this sequence */
1618+
printfPQExpBuffer(&buf,"SELECT pg_catalog.quote_ident(nspname) || '.' ||"
1619+
"\n pg_catalog.quote_ident(relname) || '.' ||"
1620+
"\n pg_catalog.quote_ident(attname)"
1621+
"\nFROM pg_catalog.pg_class c"
1622+
"\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1623+
"\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1624+
"\nINNER JOIN pg_catalog.pg_attribute a ON ("
1625+
"\n a.attrelid=c.oid AND"
1626+
"\n a.attnum=d.refobjsubid)"
1627+
"\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1628+
"\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1629+
"\n AND d.objid=%s"
1630+
"\n AND d.deptype='a'",
1631+
oid);
1632+
1633+
result=PSQLexec(buf.data, false);
1634+
if (!result)
1635+
gotoerror_return;
1636+
elseif (PQntuples(result)==1)
1637+
{
1638+
printfPQExpBuffer(&buf,_("Owned by: %s"),
1639+
PQgetvalue(result,0,0));
1640+
printTableAddFooter(&cont,buf.data);
1641+
}
1642+
/*
1643+
* If we get no rows back, don't show anything (obviously).
1644+
* We should never get more than one row back, but if we do,
1645+
* just ignore it and don't print anything.
1646+
*/
1647+
PQclear(result);
1648+
}
16121649
elseif (tableinfo.relkind=='r'||tableinfo.relkind=='f')
16131650
{
16141651
/* Footer information about a table */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp