pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
convert 'foobar'::text to the string foobar
3+ messages / 2 participants
[nested] [flat]

* convert 'foobar'::text to the string foobar
@ 2005-05-13 13:54  Guillaume Cottenceau <gc@mnc.ch>
  0 siblings, 1 reply; 3+ messages in thread

From: Guillaume Cottenceau @ 2005-05-13 13:54 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

I want to retrieve the default value of a TEXT column of a table.
So far, I had a hard time writing this query and after looking at
postgresql doc I have looked in phppgadmin source code, and am
finally using:

   SELECT adef.adsrc AS value
     FROM pg_catalog.pg_attribute a
     LEFT JOIN pg_catalog.pg_attrdef adef
            ON a.attrelid = adef.adrelid
           AND a.attnum = adef.adnum
    WHERE a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname = ?)
      AND a.attname = ?

when used with a table with a default value set by:

ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT 'foobar';

displaying that way with \d:

 column_name   | text                   | not null default 'foobar'::text

retrieved as a String in Java, I end up with "'foobar'::text"
where I'd need just the string "foobar" (without any quote).

Is there something I'm doing wrong?

Thank you.

-- 
Guillaume Cottenceau



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

* Re: convert 'foobar'::text to the string foobar
@ 2005-05-17 17:35  Kris Jurka <books@ejurka.com>
  parent: Guillaume Cottenceau <gc@mnc.ch>
  0 siblings, 1 reply; 3+ messages in thread

From: Kris Jurka @ 2005-05-17 17:35 UTC (permalink / raw)
  To: Guillaume Cottenceau <gc@mnc.ch>; +Cc: pgsql-jdbc



On Fri, 13 May 2005, Guillaume Cottenceau wrote:

> I want to retrieve the default value of a TEXT column of a table.

You might want to consider DatabaseMetaData.getColumns() and using the 
COLUMN_DEF column.

> ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT 'foobar';
> 
> displaying that way with \d:
> 
>  column_name   | text                   | not null default 'foobar'::text
> 
> retrieved as a String in Java, I end up with "'foobar'::text"
> where I'd need just the string "foobar" (without any quote).
> 

That's how it is stored internally and there's not really much we can do 
about it.  If you know it's going to be 'xxx'::sometype it would be easy 
to parse, but the driver can make no such assumptions.

Kris Jurka



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

* Re: convert 'foobar'::text to the string foobar
@ 2005-05-18 08:31  Guillaume Cottenceau <gc@mnc.ch>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Guillaume Cottenceau @ 2005-05-18 08:31 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

Kris Jurka <books 'at' ejurka.com> writes:

> On Fri, 13 May 2005, Guillaume Cottenceau wrote:
> 
> > I want to retrieve the default value of a TEXT column of a table.
> 
> You might want to consider DatabaseMetaData.getColumns() and using the 
> COLUMN_DEF column.

Ah, yes, this is cleaner. Thanks Kris.

-- 
Guillaume Cottenceau



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


end of thread, other threads:[~2005-05-18 08:31 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-05-13 13:54 convert 'foobar'::text to the string foobar Guillaume Cottenceau <gc@mnc.ch>
2005-05-17 17:35 ` Kris Jurka <books@ejurka.com>
2005-05-18 08:31   ` Guillaume Cottenceau <gc@mnc.ch>

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