pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
psql: no schema info
6+ messages / 4 participants
[nested] [flat]

* psql: no schema info
@ 2008-04-27 21:33  chester c young <chestercyoung@yahoo.com>
  0 siblings, 1 reply; 6+ messages in thread

From: chester c young @ 2008-04-27 21:33 UTC (permalink / raw)
  To: pgsql-sql

have several schemae, each with identical tables.

in create scripts have been taking great care to fully qualify, eg,
  col1 references schema1.tab1( col1 )

however, just got burnt big time on sequences!  need to qualify them as
well, eg
  col1 integer default nextval( 'schema1.seq1' )

\dt is no help at all since it does not specify schema so it's
impossible to know if all is aligned correctly.  is there a way to tell
psql to fully qualify relations in the listing?

when everything was in public this wasn't a problem, but with elaborate
use of schemae it's pretty scary (for me).


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql: no schema info
@ 2008-04-27 22:36  Tom Lane <tgl@sss.pgh.pa.us>
  parent: chester c young <chestercyoung@yahoo.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2008-04-27 22:36 UTC (permalink / raw)
  To: chester c young <chestercyoung@yahoo.com>; +Cc: pgsql-sql

chester c young <chestercyoung@yahoo.com> writes:
> however, just got burnt big time on sequences!  need to qualify them as
> well, eg
>   col1 integer default nextval( 'schema1.seq1' )

Move to something newer than 8.0.x, and this is automatic (because
nextval's argument is actually a regclass constant).

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql: no schema info
@ 2008-04-27 23:33  chester c young <chestercyoung@yahoo.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 6+ messages in thread

From: chester c young @ 2008-04-27 23:33 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql


> > however, just got burnt big time on sequences!  need to qualify
> them as
> > well, eg
> >   col1 integer default nextval( 'schema1.seq1' )
> 
> Move to something newer than 8.0.x, and this is automatic (because
> nextval's argument is actually a regclass constant).
> 
> 			regards, tom lane

using 8.2 and 8.3

here's (psychological) problem as I see it:

# set search_path=old_schema;
#
# create sequence new_schema.seq1;
#
# create table new_schema.table1(
#    col1 integer default nextval( 'seq1' )
# );

using old_schema.seq1, not new_schema.seq1

and imho to make matters more difficult to troubleshoot:

# \dt table1 -> does not show which schema for seq1



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql: no schema info
@ 2008-04-28 00:05  Alvaro Herrera <alvherre@commandprompt.com>
  parent: chester c young <chestercyoung@yahoo.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Alvaro Herrera @ 2008-04-28 00:05 UTC (permalink / raw)
  To: chester c young <chestercyoung@yahoo.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; 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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql: no schema info
@ 2008-04-28 07:30  Richard Huxton <dev@archonet.com>
  parent: chester c young <chestercyoung@yahoo.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Richard Huxton @ 2008-04-28 07:30 UTC (permalink / raw)
  To: chester c young <chestercyoung@yahoo.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-sql

chester c young wrote:
> using 8.2 and 8.3
> 
> here's (psychological) problem as I see it:
> 
> # set search_path=old_schema;
> #
> # create sequence new_schema.seq1;
> #
> # create table new_schema.table1(
> #    col1 integer default nextval( 'seq1' )
> # );
> 
> using old_schema.seq1, not new_schema.seq1
> 
> and imho to make matters more difficult to troubleshoot:
> 
> # \dt table1 -> does not show which schema for seq1

Must admit I thought you were wrong, but having tested it, I think I see 
what you mean.

If the schema in question is in the search_path then it doesn't get 
displayed. If you've forgotten what your search_path is set to then that 
can cause confusion.

Not a problem I see much of since I very rarely change my search_path. I 
  refer to schema.table by preference.

-- 
   Richard Huxton
   Archonet Ltd



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql: no schema info
@ 2008-04-28 17:01  chester c young <chestercyoung@yahoo.com>
  parent: Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 6+ messages in thread

From: chester c young @ 2008-04-28 17:01 UTC (permalink / raw)
  To: pgsql-sql

> > # \dt table1 -> does not show which schema info.

was wrong on this - \dt shows schema for relations _not_ in the search
path.

my new good practice is to keep search_path = PUBLIC so all schema info
is displayed always all the time invariably.



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2008-04-28 17:01 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-04-27 21:33 psql: no schema info chester c young <chestercyoung@yahoo.com>
2008-04-27 22:36 ` Tom Lane <tgl@sss.pgh.pa.us>
2008-04-27 23:33   ` chester c young <chestercyoung@yahoo.com>
2008-04-28 00:05     ` Alvaro Herrera <alvherre@commandprompt.com>
2008-04-28 07:30     ` Richard Huxton <dev@archonet.com>
2008-04-28 17:01       ` chester c young <chestercyoung@yahoo.com>

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