On Fri, 20 Mar 2009 13:24:06 +0100, I wrote:
[... DBD::Pg uses pg_catalog.pg_attrdef to find the default value of a
column ...]
> My question is basically where to try and get it fixed:
> * Should PostgreSQL update pg_attrdef as part of executing "ALTER
> SEQUENCE .. RENAME TO .."?
> * Should DBD::Pg get COLUMN_DEF from the same place that psql does? - or:
> * Should DBIx::Class get the default value of a column from somewhere
> else than COLUMN_DEF, if so, where?
Looking at the PostgreSQL documentation of pg_attrdef, it says:
"The adsrc field is historical, and is best not used, because it does
not track outside changes that might affect the representation of the
default value. Reverse-compiling the adbin field (with pg_get_expr for
example) is a better way to display the default value."
- http://www.postgresql.org/docs/8.3/static/catalog-pg-attrdef.html
So I guess that column_info in DBD::Pg should be updated to take that
advice into account?
Peeking at what psql does, I've put together the patch below (against
trunk).
I'm not sure how it will impact DBD::Pg running against older versions
of PostgreSQL, though.
When was pg_get_expr() created? Between 7.4 and 8.0 it seems¹, so maybe
a conditional is necessary?
Best regards,
Adam
¹ http://www.postgresql.org/docs/7.4/static/catalog-pg-attrdef.html
http://www.postgresql.org/docs/8.0/static/catalog-pg-attrdef.html
--
Adam Sjøgren
[email protected]
diff --git a/Pg.pm b/Pg.pm
index 0e9ba91..c08ad17 100644
--- a/Pg.pm
+++ b/Pg.pm
@@ -447,7 +447,7 @@ use 5.006001;
, NULL::text AS "NUM_PREC_RADIX"
, CASE a.attnotnull WHEN 't' THEN 0 ELSE 1 END AS "NULLABLE"
, $remarks AS "REMARKS"
- , af.adsrc AS "COLUMN_DEF"
+ , pg_catalog.pg_get_expr(af.adbin, af.adrelid) AS "COLUMN_DEF"
, NULL::text AS "SQL_DATA_TYPE"
, NULL::text AS "SQL_DATETIME_SUB"
, NULL::text AS "CHAR_OCTET_LENGTH"