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

Commit1ac7db4

Browse files
committed
I can't remember who said they were working on schema related psql
changes, but I kept finding myself wishing I could see what schema atable or view exists in when I use \dt, \dv, etc. So, here is a patchwhich does just that.It sorts on "Schema" first, and "Name" second.It also changes the test for system objects to key off the namespacename starting with 'pg_' instead of the object name.Sample output:test=# create schema testschema;CREATE SCHEMAtest=# create view testschema.ts_view as select 1;CREATE VIEWtest=# \dv List of relations Name | Schema | Type | Owner--------------------+------------+------+---------- __testpassbyval | public | view | postgres fooview | public | view | postgres master_pg_proc | public | view | postgres rmt_pg_proc | public | view | postgres vw_dblink_get_pkey | public | view | postgres vw_dblink_replace | public | view | postgres ts_view | testschema | view | postgres(7 rows)Joe Conway
1 parent1ce0360 commit1ac7db4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

‎src/bin/psql/describe.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.55 2002/07/12 18:43:19 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.56 2002/07/20 05:57:31 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -1022,9 +1022,10 @@ listTables(const char *infotype, const char *name, bool desc)
10221022

10231023
printfPQExpBuffer(&buf,
10241024
"SELECT c.relname as \"%s\",\n"
1025+
" n.nspname as \"%s\",\n"
10251026
" CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' WHEN 's' THEN '%s' END as \"%s\",\n"
10261027
" u.usename as \"%s\"",
1027-
_("Name"),_("table"),_("view"),_("index"),_("sequence"),
1028+
_("Name"),_("Schema"),_("table"),_("view"),_("index"),_("sequence"),
10281029
_("special"),_("Type"),_("Owner"));
10291030

10301031
if (desc)
@@ -1034,14 +1035,16 @@ listTables(const char *infotype, const char *name, bool desc)
10341035
if (showIndexes)
10351036
appendPQExpBuffer(&buf,
10361037
",\n c2.relname as \"%s\""
1037-
"\nFROM pg_class c, pg_class c2, pg_index i, pg_user u\n"
1038+
"\nFROM pg_class c, pg_class c2, pg_index i, pg_user u, pg_namespace n\n"
10381039
"WHERE c.relowner = u.usesysid\n"
1040+
"AND c.relnamespace = n.oid\n"
10391041
"AND i.indrelid = c2.oid AND i.indexrelid = c.oid\n",
10401042
_("Table"));
10411043
else
10421044
appendPQExpBuffer(&buf,
1043-
"\nFROM pg_class c, pg_user u\n"
1044-
"WHERE c.relowner = u.usesysid\n");
1045+
"\nFROM pg_class c, pg_user u, pg_namespace n\n"
1046+
"WHERE c.relowner = u.usesysid\n"
1047+
"AND c.relnamespace = n.oid\n");
10451048

10461049
appendPQExpBuffer(&buf,"AND c.relkind IN (");
10471050
if (showTables)
@@ -1058,14 +1061,14 @@ listTables(const char *infotype, const char *name, bool desc)
10581061
appendPQExpBuffer(&buf,")\n");
10591062

10601063
if (showSystem)
1061-
appendPQExpBuffer(&buf," ANDc.relname ~ '^pg_'\n");
1064+
appendPQExpBuffer(&buf," ANDn.nspname ~ '^pg_'\n");
10621065
else
1063-
appendPQExpBuffer(&buf," ANDc.relname !~ '^pg_'\n");
1066+
appendPQExpBuffer(&buf," ANDn.nspname !~ '^pg_'\n");
10641067

10651068
if (name)
10661069
appendPQExpBuffer(&buf," AND c.relname ~ '^%s'\n",name);
10671070

1068-
appendPQExpBuffer(&buf,"ORDER BY 1;");
1071+
appendPQExpBuffer(&buf,"ORDER BY2,1;");
10691072

10701073
res=PSQLexec(buf.data);
10711074
termPQExpBuffer(&buf);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp