Re: Finding the sequence used for a primary key, after renaming it

[email protected] (Adam Sjøgren)
Newsgroups gmane.comp.db.postgresql.dbdpg
Organization Novozymes A/S (reg. no.: 10007127)
Message-ID <[email protected]>
On Tue, 24 Mar 2009 15:54:21 +0100, I wrote:

> When was pg_get_expr() created? Between 7.4 and 8.0 it seems¹, so maybe
> a conditional is necessary?

Attached is a patch that uses pg_get_expr() for 8.0+ and adsrc
otherwise.


  Best regards,

    Adam

-- 
                                                          Adam Sjøgren
                                                    [email protected]
use-pg_get_expr-instead-of-adsrc-for-COLUMN_DEF-in.patch (text/x-diff, 726 B)
diff --git a/Pg.pm b/Pg.pm
index 0e9ba91..022d53a 100644
--- a/Pg.pm
+++ b/Pg.pm
@@ -433,6 +433,8 @@ use 5.006001;
 
 		my $remarks = 'pg_catalog.col_description(a.attrelid, a.attnum)';
 
+		my $column_def = $dbh->{pg_server_version}>=80000 ? 'pg_catalog.pg_get_expr(af.adbin, af.adrelid)' : 'af.adsrc';
+
 		my $col_info_sql = qq!
 			SELECT
 				NULL::text AS "TABLE_CAT"
@@ -447,7 +449,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"
+				, $column_def AS "COLUMN_DEF"
 				, NULL::text AS "SQL_DATA_TYPE"
 				, NULL::text AS "SQL_DATETIME_SUB"
 				, NULL::text AS "CHAR_OCTET_LENGTH"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.