Re: Strange "missing tables" problem

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Denis BUCHER <dbucherml(at)hsolutions(dot)ch>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Strange "missing tables" problem
Date: 2009-08-24 09:37:34
Message-ID: 200908241137.34194.guillaume@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Denis,

Le lundi 24 août 2009 à 10:21:33, Denis BUCHER a écrit :
> > [...]
> > I suppose you have something like 'rma, import, ...' for search_path, so
> > it only displays rma.customers and not impor.customers.
>
> Yes that's correct. Therefore my "problem" is the "normal" behavior of
> \dt. But "normal" means "expected". But I don't find it very
> secure/handy, because you expect to see all your tables. Is there a way
> to change the behavior of \dt so that it lists ALL tables present in
> search path ?
>

No. But you can always take a look a this:

http://radek.cc/2009/08/15/psqlrc-tricks-table-sizes/

You can probably do a \set dt your_query, and then :dt; instead of \dt. ... a
few moments later... I tried and it works.

Put this line in your .psqlrc file:
\set dt '(SELECT n.nspname as \"Schéma\", c.relname as \"Nom\", CASE c.relkind
WHEN \'r\' THEN \'table\' WHEN \'v\' THEN \'vue\' WHEN \'i\' THEN \'index\'
WHEN \'S\' THEN \'séq uence\' WHEN \'s\' THEN \'spécial\' END as \"Type\",
r.rolname as \"Propriétaire\" FROM pg_catalog.pg_class c JOIN
pg_catalog.pg_roles r ON r.oid = c.relowner LEFT JOIN pg_cata
log.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN (\'r\',\'\')
AND n.nspname NOT IN (\'pg_catalog\', \'pg_toast\') ORDER BY 1,2)'

It should be one line only, and you can add more schemas on the n.nspname
filter (information_schema for example).

Now, I get this with this .psqlrc trick:

guillaume(at)laptop:~$ psql -q a
a=# set search_path to public, toto;
a=# \dt
Liste des relations
Schéma | Nom | Type | Propriétaire
--------+-----+-------+--------------
public | t1 | table | ab1
public | t2 | table | a2
public | t3 | table | postgres
toto | t4 | table | guillaume
(4 lignes)

a=# :dt;
Schéma | Nom | Type | Propriétaire
--------------------+-------------------------+-------+--------------
information_schema | sql_features | table | guillaume
information_schema | sql_implementation_info | table | guillaume
information_schema | sql_languages | table | guillaume
information_schema | sql_packages | table | guillaume
information_schema | sql_sizing | table | guillaume
information_schema | sql_sizing_profiles | table | guillaume
pgagent | pga_exception | table | guillaume
pgagent | pga_job | table | guillaume
pgagent | pga_jobagent | table | guillaume
pgagent | pga_jobclass | table | guillaume
pgagent | pga_joblog | table | guillaume
pgagent | pga_jobstep | table | guillaume
pgagent | pga_jobsteplog | table | guillaume
pgagent | pga_schedule | table | guillaume
public | t1 | table | ab1
public | t2 | table | a2
public | t3 | table | postgres
toto | t1 | table | guillaume
toto | t4 | table | guillaume
(19 lignes)

Hope it helps.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2009-08-24 10:54:31 Re: how to return field based on field= NULL or not
Previous Message Fred Janon 2009-08-24 09:24:59 How to create a multi-column index with 2 dates using 'gist'?