detecting serials in 8.1 - Mailing list pgadmin-hackers

From Kris Jurka
Subject detecting serials in 8.1
Date
Msg-id dtac7k$23kr$1@news.hub.org
Whole thread Raw
Responses Re: detecting serials in 8.1  (Andreas Pflug <pgadmin@pse-consulting.de>)
List pgadmin-hackers
8.1 has changed the default text for serials from something like
nextval('public.tab_col_seq'::text) to nextval('tab_col_seq'::regclass)

Kris Jurka
Index: src/schema/pgColumn.cpp
===================================================================
*** src/schema/pgColumn.cpp    (revision 5006)
--- src/schema/pgColumn.cpp    (working copy)
***************
*** 126,136 ****
  {
      wxString sql = GetQuotedTypename();

      if ((sql == wxT("int4") || sql == wxT("int8") ||
           sql == wxT("pg_catalog.int4") || sql == wxT("pg_catalog.int8"))
!         && GetDefault() == wxT("nextval('")
!                         + schema->GetName() + wxT(".") + GetTableName()
!                         + wxT("_") + GetName() + wxT("_seq'::text)"))
      {
          if (sql.Right(4) == wxT("int8"))
              sql = wxT("bigserial");
--- 126,150 ----
  {
      wxString sql = GetQuotedTypename();

+     // Technically this serial check can still fail for sequences that
+     // get created with non-default names.  Consider:
+     // CREATE SEQUENCE st_a_seq;
+     // CREATE TABLE st (a serial);
+     // Now the default's sequence is actually st_a_seq1.
+
+     wxString sequenceDefault;
+     if (GetDatabase()->BackendMinimumVersion(8, 1)) {
+         sequenceDefault = wxT("nextval('") + GetTableName()
+                         + wxT("_") + GetName() + wxT("_seq'::regclass)");
+     } else {
+         sequenceDefault = wxT("nextval('")
+                         + schema->GetName() + wxT(".") + GetTableName()
+                         + wxT("_") + GetName() + wxT("_seq'::text)");
+     }
+
      if ((sql == wxT("int4") || sql == wxT("int8") ||
           sql == wxT("pg_catalog.int4") || sql == wxT("pg_catalog.int8"))
!         && GetDefault() == sequenceDefault)
      {
          if (sql.Right(4) == wxT("int8"))
              sql = wxT("bigserial");

pgadmin-hackers by date:

Previous
From: Kris Jurka
Date:
Subject: Re: SVN Commit by dpage: r5003 - in trunk/pgadmin3: . src/base
Next
From: "Magnus Hagander"
Date:
Subject: Re: select inside transactions