Re: psql: no schema info - Mailing list pgsql-sql

From Alvaro Herrera
Subject Re: psql: no schema info
Date
Msg-id 20080428000541.GC9074@alvh.no-ip.org
Whole thread Raw
In response to Re: psql: no schema info  (chester c young <chestercyoung@yahoo.com>)
List pgsql-sql
chester c young wrote:

> # create table new_schema.table1(
> #    col1 integer default nextval( 'seq1' )
> # );
> 
> using old_schema.seq1, not new_schema.seq1

Yes, that's correct -- assuming you had an old_schema.seq1 sequence too.

> and imho to make matters more difficult to troubleshoot:
> 
> # \dt table1 -> does not show which schema for seq1

I agree it can be confusing if you're not looking for it.

alvherre=# set search_path to old_s;
SET
alvherre=# \d new_s.table1                Tabla «new_s.table1»Columna |  Tipo   |           Modificadores           
---------+---------+-----------------------------------col1    | integer | default nextval('seq1'::regclass)

Here, the nextval() is correctly _not_ qualified, because the current
search path is the sequence's schema.  But it is certainly confusing.

You have to set the search_path to the table's search path for the
problem to be obvious:

alvherre=# set search_path to new_s;
SET
alvherre=# \d new_s.table1                   Tabla «new_s.table1»Columna |  Tipo   |              Modificadores
    
 
---------+---------+-----------------------------------------col1    | integer | default
nextval('old_s.seq1'::regclass)

alvherre=# \d table1                   Tabla «new_s.table1»Columna |  Tipo   |              Modificadores

---------+---------+-----------------------------------------col1    | integer | default
nextval('old_s.seq1'::regclass)


I'm not sure what's a good solution here.  Perhaps the \d command should
temporarily set the schema to something that would cause regclass to
display qualified names all the time, when you passed it a qualified
name (using SET LOCAL perhaps, but reverting to the original value after
then \d is done).  You can't just use a nonexistant schema or some kind
of NULL or empty value, because SET rejects it.  I can set it to $user,
which is accepted but doesn't exist on my scratch database:

alvherre=# set search_path to '$user';
SET
alvherre=# \d new_s.table1                   Tabla «new_s.table1»Columna |  Tipo   |              Modificadores
    
 
---------+---------+-----------------------------------------col1    | integer | default
nextval('old_s.seq1'::regclass)


Another option would be to set it to the given schema, so that any name
not on that schema is qualified.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: psql: no schema info
Next
From: Emi Lu
Date:
Subject: Re: trim(both) problem?