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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

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: Sun, 27 Apr 2008 20:05:41 -0400
  • Message-id: <20080428000541.GC9074@alvh.no-ip.org> <text/plain>

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



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group