pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedRenaming sequence auto generated by SERIAL type don't update pg_attrdef
10+ messages / 4 participants
[nested] [flat]
* Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-10 01:55 Dickson S. Guedes <listas@guedesoft.net>
0 siblings, 1 reply; 10+ messages in thread
From: Dickson S. Guedes @ 2009-03-10 01:55 UTC (permalink / raw)
To: pgsql-jdbc
Hi all,
Reproduced in 8.3.6.
postgres=# CREATE TABLE test (a serial);
NOTICE: CREATE TABLE will create implicit sequence "test_a_seq" for
serial column "test.a"
CREATE TABLE
postgres=# \d test
Tabela "public.test"
Coluna | Tipo | Modificadores
--------+---------+--------------------------------------------------
a | integer | not null default nextval('test_a_seq'::regclass)
postgres=# ALTER SEQUENCE test_a_seq RENAME TO seq_test_another;
ALTER SEQUENCE
postgres=# \d test
Tabela "public.test"
Coluna | Tipo |
Modificadores
--------+---------+--------------------------------------------------------
a | integer | not null default
nextval('seq_test_another'::regclass)
postgres=# \x
postgres=#
postgres=# -- A sample select used by JDBC Driver for PostgreSQL
postgres=#
postgres=# SELECT n.nspname, c.relname, a.attname, a.atttypid,
a.attnotnull, a.atttypmod, a.attlen, a.attnum, def.adsrc,
dsc.description, t.typbasetype, t.typtype
postgres-# FROM pg_catalog.pg_namespace n
postgres-# JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid)
postgres-# JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid)
postgres-# JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid)
postgres-# LEFT JOIN pg_catalog.pg_attrdef def ON
(a.attrelid=def.adrelid AND a.attnum = def.adnum)
postgres-# LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid
AND a.attnum = dsc.objsubid)
postgres-# LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND
dc.relname='pg_class')
postgres-# LEFT JOIN pg_catalog.pg_namespace dn ON
(dc.relnamespace=dn.oid AND dn.nspname='pg_catalog')
postgres-# WHERE
postgres-# a.attnum > 0 AND
postgres-# NOT a.attisdropped AND
postgres-# n.nspname LIKE 'public' AND
postgres-# c.relname LIKE 'test' AND
postgres-# a.attname LIKE '%'
postgres-# ORDER BY nspname,relname,attnum
postgres-# ;
-[ RECORD 1 ]--------------------------------
nspname | public
relname | test
attname | a
atttypid | 23
attnotnull | t
atttypmod | -1
attlen | 4
attnum | 1
adsrc | nextval('test_a_seq'::regclass)
description |
typbasetype | 0
typtype | b
Shouldn't the JDBC driver use another query instead that, since docs
alerts[1] to this problem?
[1]
http://www.postgresql.org/docs/current/static/catalog-pg-attrdef.html
Regards,
--
Dickson S. Guedes
mail/xmpp: guedes@guedesoft.net - skype: guediz
http://guedesoft.net - http://planeta.postgresql.org.br
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-10 03:28 Tom Lane <tgl@sss.pgh.pa.us>
parent: Dickson S. Guedes <listas@guedesoft.net>
0 siblings, 2 replies; 10+ messages in thread
From: Tom Lane @ 2009-03-10 03:28 UTC (permalink / raw)
To: Dickson S. Guedes <listas@guedesoft.net>; +Cc: pgsql-jdbc
"Dickson S. Guedes" <listas@guedesoft.net> writes:
> Shouldn't the JDBC driver use another query instead that, since docs
> alerts[1] to this problem?
What's the default value being used for anyway? If it's to determine
which sequence is associated with the column, I think you shouldn't be
looking at pg_attrdef at all; you should look for a dependent sequence
via pg_depend. But maybe it's only being used to check if the column
has a default, in which case the possible staleness of the string
value isn't important.
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-10 03:44 Oliver Jowett <oliver@opencloud.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 10+ messages in thread
From: Oliver Jowett @ 2009-03-10 03:44 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Dickson S. Guedes <listas@guedesoft.net>; pgsql-jdbc
Tom Lane wrote:
> "Dickson S. Guedes" <listas@guedesoft.net> writes:
>> Shouldn't the JDBC driver use another query instead that, since docs
>> alerts[1] to this problem?
>
> What's the default value being used for anyway? If it's to determine
> which sequence is associated with the column, I think you shouldn't be
> looking at pg_attrdef at all; you should look for a dependent sequence
> via pg_depend. But maybe it's only being used to check if the column
> has a default, in which case the possible staleness of the string
> value isn't important.
I'm guessing that particular query is from
DatabaseMetaData.getColumns(), which returns amongst other things:
13. COLUMN_DEF String => default value (may be null)
(yes, that's the sum total of the JDBC documentation about that piece of
metadata)
-O
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-10 03:54 Tom Lane <tgl@sss.pgh.pa.us>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 1 reply; 10+ messages in thread
From: Tom Lane @ 2009-03-10 03:54 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: Dickson S. Guedes <listas@guedesoft.net>; pgsql-jdbc
Oliver Jowett <oliver@opencloud.com> writes:
> Tom Lane wrote:
>> What's the default value being used for anyway?
> I'm guessing that particular query is from
> DatabaseMetaData.getColumns(), which returns amongst other things:
> 13. COLUMN_DEF String => default value (may be null)
> (yes, that's the sum total of the JDBC documentation about that piece of
> metadata)
Hmm. The correct, pg_dump-tested way to get the default expression is
pg_catalog.pg_get_expr(adbin, adrelid)
but that's fairly expensive. I'm having a hard time recommending
that you put it into DatabaseMetaData.getColumns, when probably 99.99%
of applications won't even look at the value let alone care if it is
stale. OTOH the joins involved are not-cheap already, so maybe this
worry is just premature micro-optimization.
BTW, is there a reason for the query to be using LIKE 'name' instead of
= 'name'? And if so, is whatever generates it smart about underscores
and % and \ in the name?
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-10 04:06 Oliver Jowett <oliver@opencloud.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 10+ messages in thread
From: Oliver Jowett @ 2009-03-10 04:06 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Dickson S. Guedes <listas@guedesoft.net>; pgsql-jdbc
Tom Lane wrote:
> Hmm. The correct, pg_dump-tested way to get the default expression is
> pg_catalog.pg_get_expr(adbin, adrelid)
> but that's fairly expensive. I'm having a hard time recommending
> that you put it into DatabaseMetaData.getColumns, when probably 99.99%
> of applications won't even look at the value let alone care if it is
> stale. OTOH the joins involved are not-cheap already, so maybe this
> worry is just premature micro-optimization.
I don't think DBMD.getColumns() is expected to be called all that much,
certainly not in performance-critical paths, so perhaps the more complex
expression is the way to go. How far back, version-wise, will that
expression work?
> BTW, is there a reason for the query to be using LIKE 'name' instead of
> = 'name'? And if so, is whatever generates it smart about underscores
> and % and \ in the name?
The API lets the application specify a pattern to search on, using the
same syntax that LIKE expects, so the driver just passes it straight
through into the query (modulo normal string escaping)
-O
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-10 04:37 Tom Lane <tgl@sss.pgh.pa.us>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 1 reply; 10+ messages in thread
From: Tom Lane @ 2009-03-10 04:37 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: Dickson S. Guedes <listas@guedesoft.net>; pgsql-jdbc
Oliver Jowett <oliver@opencloud.com> writes:
> Tom Lane wrote:
>> pg_catalog.pg_get_expr(adbin, adrelid)
> I don't think DBMD.getColumns() is expected to be called all that much,
> certainly not in performance-critical paths, so perhaps the more complex
> expression is the way to go. How far back, version-wise, will that
> expression work?
According to the pg_dump sources, that's good back to 7.3 ... do you
care about earlier?
>> BTW, is there a reason for the query to be using LIKE 'name' instead of
>> = 'name'? And if so, is whatever generates it smart about underscores
>> and % and \ in the name?
> The API lets the application specify a pattern to search on, using the
> same syntax that LIKE expects, so the driver just passes it straight
> through into the query (modulo normal string escaping)
Fair enough. I was just trying to remember whether the planner was
smart enough to consider LIKE 'constant-pattern' to be equivalent to
= 'constant-pattern' even when the locale prevents doing anything
smarter for non-constant patterns. But that'd be my problem to fix not
yours ...
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-10 12:00 Dickson S. Guedes <listas@guedesoft.net>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 10+ messages in thread
From: Dickson S. Guedes @ 2009-03-10 12:00 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-jdbc
Em Seg, 2009-03-09 às 23:28 -0400, Tom Lane escreveu:
> But maybe it's only being used to check if the column
> has a default, in which case the possible staleness of the string
> value isn't important.
Some Java programs (as DBVis and Aqua for example), are using it to get
column default value, but are showing an old information after we rename
the sequence.
Regards,
Dickson S. Guedes
mail/xmpp: guedes@guedesoft.net - skype: guediz
http://guedesoft.net - http://planeta.postgresql.org.br
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-12 04:02 Kris Jurka <books@ejurka.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 10+ messages in thread
From: Kris Jurka @ 2009-03-12 04:02 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Oliver Jowett <oliver@opencloud.com>; Dickson S. Guedes <listas@guedesoft.net>; pgsql-jdbc
On Tue, 10 Mar 2009, Tom Lane wrote:
> Oliver Jowett <oliver@opencloud.com> writes:
>> Tom Lane wrote:
>>> pg_catalog.pg_get_expr(adbin, adrelid)
>
>> I don't think DBMD.getColumns() is expected to be called all that much,
>> certainly not in performance-critical paths, so perhaps the more complex
>> expression is the way to go. How far back, version-wise, will that
>> expression work?
>
> According to the pg_dump sources, that's good back to 7.3 ... do you
> care about earlier?
It works for 7.2 as well. Prior to that we'll continue using adsrc.
Committed to CVS and backpatched to 8.0.
Kris Jurka
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-12 12:25 Tom Lane <tgl@sss.pgh.pa.us>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 10+ messages in thread
From: Tom Lane @ 2009-03-12 12:25 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: Oliver Jowett <oliver@opencloud.com>; Dickson S. Guedes <listas@guedesoft.net>; pgsql-jdbc
Kris Jurka <books@ejurka.com> writes:
> On Tue, 10 Mar 2009, Tom Lane wrote:
>>> pg_catalog.pg_get_expr(adbin, adrelid)
>>
>> According to the pg_dump sources, that's good back to 7.3 ... do you
>> care about earlier?
> It works for 7.2 as well.
Er, not with the pg_catalog qualifier ...
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Renaming sequence auto generated by SERIAL type don't update pg_attrdef
@ 2009-03-13 04:50 Kris Jurka <books@ejurka.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 10+ messages in thread
From: Kris Jurka @ 2009-03-13 04:50 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Oliver Jowett <oliver@opencloud.com>; Dickson S. Guedes <listas@guedesoft.net>; pgsql-jdbc
Tom Lane wrote:
> Kris Jurka <books@ejurka.com> writes:
>> It works for 7.2 as well.
>
> Er, not with the pg_catalog qualifier ...
>
I was just referring to pg_get_expr, naturally the 7.2 codepath doesn't
use the schema.
Kris Jurka
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2009-03-13 04:50 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-03-10 01:55 Renaming sequence auto generated by SERIAL type don't update pg_attrdef Dickson S. Guedes <listas@guedesoft.net>
2009-03-10 03:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-03-10 03:44 ` Oliver Jowett <oliver@opencloud.com>
2009-03-10 03:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-03-10 04:06 ` Oliver Jowett <oliver@opencloud.com>
2009-03-10 04:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-03-12 04:02 ` Kris Jurka <books@ejurka.com>
2009-03-12 12:25 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-03-13 04:50 ` Kris Jurka <books@ejurka.com>
2009-03-10 12:00 ` Dickson S. Guedes <listas@guedesoft.net>
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