pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14317: psql \dt not working as expected
3+ messages / 3 participants
[nested] [flat]

* BUG #14317: psql \dt not working as expected
@ 2016-09-08 15:40  lucian.ciufudean@gmail.com
  0 siblings, 2 replies; 3+ messages in thread

From: lucian.ciufudean@gmail.com @ 2016-09-08 15:40 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14317
Logged by:          Lucian Ciufudean
Email address:      lucian.ciufudean@gmail.com
PostgreSQL version: 9.5.4
Operating system:   windows 7 x64
Description:        

If one creates a table with the same name as one of the pg_catalog tables

1. CREATE TABLE pg_tables (
    name            varchar(80),
    location        point
);

then \dt will not show it:

         List of relations
 Schema |  Name  | Type  |  Owner
--------+--------+-------+----------
 public | cities | table | postgres
(1 row)

while this query will:

select * from pg_tables;

Expectations: \dt shows all tables in the public schema.

Note that it is also unexpected that this query:

select * from pg_tables;

goes to pg_catalog.pg_tables instead of public.pg_tables.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14317: psql \dt not working as expected
@ 2016-09-08 15:46  John R Pierce <pierce@hogranch.com>
  parent: lucian.ciufudean@gmail.com
  1 sibling, 0 replies; 3+ messages in thread

From: John R Pierce @ 2016-09-08 15:46 UTC (permalink / raw)
  To: lucian.ciufudean@gmail.com; pgsql-bugs

On 9/8/2016 8:40 AM, lucian.ciufudean@gmail.com wrote:
> If one creates a table with the same name as one of the pg_catalog tables
>
> 1. CREATE TABLE pg_tables (
>      name            varchar(80),
>      location        point
> );
>
> then \dt will not show it:
>
>           List of relations
>   Schema |  Name  | Type  |  Owner
> --------+--------+-------+----------
>   public | cities | table | postgres
> (1 row)
>
> while this query will:
>
> select * from pg_tables;
>
> Expectations: \dt shows all tables in the public schema.
>
> Note that it is also unexpected that this query:
>
> select * from pg_tables;
>
> goes to pg_catalog.pg_tables instead of public.pg_tables.

this is because pg_catalog is implicitly in the search path in front of 
any explicit search path you specify, including the default of 
`$user,public` ...

suggestion:  don't use names like pg_XXXXX for anything.


-- 
john r pierce, recycling bits in santa cruz



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14317: psql \dt not working as expected
@ 2016-09-08 15:52  Tom Lane <tgl@sss.pgh.pa.us>
  parent: lucian.ciufudean@gmail.com
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2016-09-08 15:52 UTC (permalink / raw)
  To: lucian.ciufudean@gmail.com; +Cc: pgsql-bugs

lucian.ciufudean@gmail.com writes:
> If one creates a table with the same name as one of the pg_catalog tables
> then \dt will not show it:

This is expected, if you are using the default search_path, because
pg_catalog will be in front of public and will mask your version of
pg_tables.

> Expectations: \dt shows all tables in the public schema.

Nope, \dt shows *visible* tables, ie those that can be referenced without
schema qualification.  See this bit in the psql documentation:

       Whenever the pattern parameter is omitted completely, the \d
       commands display all objects that are visible in the current schema
       search path — this is equivalent to using * as the pattern. (An
       object is said to be visible if its containing schema is in the
       search path and no object of the same kind and name appears earlier
       in the search path. This is equivalent to the statement that the
       object can be referenced by name without explicit schema
       qualification.) To see all objects in the database regardless of
       visibility, use *.* as the pattern.

> Note that it is also unexpected that this query:
> select * from pg_tables;
> goes to pg_catalog.pg_tables instead of public.pg_tables.

Again, you are confused about how the search path works.

If you really want to, you can put public in front of pg_catalog
in your search path, but it's not recommendable --- it's a security
hazard, for one thing.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2016-09-08 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-09-08 15:40 BUG #14317: psql \dt not working as expected lucian.ciufudean@gmail.com
2016-09-08 15:46 ` John R Pierce <pierce@hogranch.com>
2016-09-08 15:52 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox