pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@commandprompt.com>
To: chester c young <chestercyoung@yahoo.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: sql pgsql <pgsql-sql@postgresql.org>
Subject: Re: psql: no schema info
Date: Sun, 27 Apr 2008 20:05:41 -0400
Message-ID: <20080428000541.GC9074@alvh.no-ip.org> (raw)
In-Reply-To: <213749.31261.qm@web54304.mail.re2.yahoo.com>
References: <23267.1209335819@sss.pgh.pa.us>
	<213749.31261.qm@web54304.mail.re2.yahoo.com>

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



view thread (6+ messages)  latest in thread

Message-ID: <20080428000541.GC9074@alvh.no-ip.org>
Permalink:  ../20080428000541.GC9074@alvh.no-ip.org/
Also on:    postgresql.org/message-id/20080428000541.GC9074@alvh.no-ip.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: alvherre@commandprompt.com, chestercyoung@yahoo.com, tgl@sss.pgh.pa.us
  Subject: Re: psql: no schema info
  In-Reply-To: <20080428000541.GC9074@alvh.no-ip.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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