Skip site navigation (1) Skip section navigation (2)

Re: psql: no schema info

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: chester c young <chestercyoung(at)yahoo(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, sql pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: psql: no schema info
Date: 2008-04-28 00:05:41
Message-ID: 20080428000541.GC9074@alvh.no-ip.org (view raw or flat)
Thread:
Lists: 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

In response to

pgsql-sql by date

Next:From: Richard HuxtonDate: 2008-04-28 07:30:09
Subject: Re: psql: no schema info
Previous:From: chester c youngDate: 2008-04-27 23:33:26
Subject: Re: psql: no schema info

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group