Issue with listing same tablenames from different schemas in the search_path

Started by Nikhil Sontakkeover 14 years ago3 messages
#1Nikhil Sontakke
nikkhils@gmail.com

Hi,

Consider the following sequence of commands in a psql session:

postgres=#create table public.sample(x int);
postgres=#create schema new;
postgres=#create table new.sample(x int);
postgres=#set search_path=public,new;

postgres=#\dt
Schema | Name | Type | Owner
-------------------------------------------
public | sample | table | postgres
(1 row)

We should have seen two entries in the above listing. So looks like a bug to
me.

The issue is with the call to pg_table_is_visible(). While scanning for the
second entry, it breaks out because there is a matching entry with the same
name in the first schema. What we need is a variation of this function which
checks for visibility of the corresponding namespace in the search path and
emit it out too if so.

Thoughts? I can cook up a patch for this.

Regards,
Nikhils

#2Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Nikhil Sontakke (#1)
Re: Issue with listing same tablenames from different schemas in the search_path

On 02.10.2011 08:31, Nikhil Sontakke wrote:

Consider the following sequence of commands in a psql session:

postgres=#create table public.sample(x int);
postgres=#create schema new;
postgres=#create table new.sample(x int);
postgres=#set search_path=public,new;

postgres=#\dt
Schema | Name | Type | Owner
-------------------------------------------
public | sample | table | postgres
(1 row)

We should have seen two entries in the above listing. So looks like a bug to
me.

No, that's the way it's designed to work. It shows the objects that are
visible to you, without schema-qualifying them. See
http://www.postgresql.org/docs/9.0/interactive/app-psql.html#APP-PSQL-PATTERNS
:

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.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

#3Nikhil Sontakke
nikkhils@gmail.com
In reply to: Heikki Linnakangas (#2)
Re: Issue with listing same tablenames from different schemas in the search_path

postgres=#create table public.sample(x int);

postgres=#create schema new;

postgres=#create table new.sample(x int);
postgres=#set search_path=public,new;

postgres=#\dt
Schema | Name | Type | Owner
------------------------------**-------------
public | sample | table | postgres
(1 row)

We should have seen two entries in the above listing. So looks like a bug
to
me.

No, that's the way it's designed to work. It shows the objects that are
visible to you, without schema-qualifying them. See
http://www.postgresql.org/**docs/9.0/interactive/app-psql.**
html#APP-PSQL-PATTERNS<http://www.postgresql.org/docs/9.0/interactive/app-psql.html#APP-PSQL-PATTERNS&gt;:

Hmmm, ok. Makes sense after reading the documentation, but seems a bit
surprising/confusing at first glance. Never mind.

Regards,
Nikhils

Show quoted text

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.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com