Hi list,

Quite recently I stumbled upon this bug in pgAdminIII and today I was
reading Guillaume Lelarge's article about pgAdmin's git repository and
this is the result. :)

The patch is attached, or you can also get it at
http://github.com/intgr/pgadmin3 branch "mybugfix"

Regards,
Marti

----
Commit message:
Fix CREATE INDEX/CONSTRAINT syntax when tablespace and fillfactor are specified

Reverse the order of TABLESPACE and WITH() clauses for indexes.  Previously
pgAdminIII generated CREATE scripts like:

ALTER TABLE foo ADD CONSTRAINT foo_pkey PRIMARY KEY(foo_id)
  USING INDEX TABLESPACE bar WITH (FILLFACTOR=50);
CREATE INDEX foo_foo_id ON foo USING btree (foo_id)
  TABLESPACE bar WITH (FILLFACTOR=50);

However these are illegal PostgreSQL syntax, the WITH() clause must come before
TABLESPACE.

The statements generated by "new index" or "new primary key" dialogs are
already correct.
From 832cab78796e12066e9ae5cf1ddf8fb75d295ae3 Mon Sep 17 00:00:00 2001
From: Marti Raudsepp <[email protected]>
Date: Wed, 6 Oct 2010 00:07:04 +0300
Subject: [PATCH] Fix CREATE INDEX/CONSTRAINT syntax when tablespace and fillfactor are specified

Reverse the order of TABLESPACE and WITH() clauses for indexes.  Previously
pgAdminIII generated CREATE scripts like:

ALTER TABLE foo ADD CONSTRAINT foo_pkey PRIMARY KEY(foo_id)
  USING INDEX TABLESPACE bar WITH (FILLFACTOR=50);
CREATE INDEX foo_foo_id ON foo USING btree (foo_id)
  TABLESPACE bar WITH (FILLFACTOR=50);

However these are illegal PostgreSQL syntax, the WITH() clause must come before
TABLESPACE.

The statements generated by "new index" or "new primary key" dialogs are
already correct.
---
 pgadmin/schema/pgIndex.cpp           |    6 +++---
 pgadmin/schema/pgIndexConstraint.cpp |    6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/pgadmin/schema/pgIndex.cpp b/pgadmin/schema/pgIndex.cpp
index 51999a6..ad520f7 100644
--- a/pgadmin/schema/pgIndex.cpp
+++ b/pgadmin/schema/pgIndex.cpp
@@ -132,12 +132,12 @@ wxString pgIndexBase::GetCreate()
 
     str += wxT(")");
 
-    if (GetConnection()->BackendMinimumVersion(8, 0) && tablespace != GetDatabase()->GetDefaultTablespace())
-        str += wxT("\nTABLESPACE ") + qtIdent(tablespace);
-
     if (GetConnection()->BackendMinimumVersion(8, 2) && GetFillFactor().Length() > 0)
         str += wxT("\n  WITH (FILLFACTOR=") + GetFillFactor() + wxT(")");
 
+    if (GetConnection()->BackendMinimumVersion(8, 0) && tablespace != GetDatabase()->GetDefaultTablespace())
+        str += wxT("\nTABLESPACE ") + qtIdent(tablespace);
+
     AppendIfFilled(str, wxT("\n  WHERE "), GetConstraint());
 
     str += wxT(";\n");
diff --git a/pgadmin/schema/pgIndexConstraint.cpp b/pgadmin/schema/pgIndexConstraint.cpp
index fec9d4b..10d1bba 100644
--- a/pgadmin/schema/pgIndexConstraint.cpp
+++ b/pgadmin/schema/pgIndexConstraint.cpp
@@ -110,12 +110,12 @@ wxString pgIndexConstraint::GetDefinition()
 
      sql += wxT("(") + GetQuotedColumns() + wxT(")");
 
-    if (GetConnection()->BackendMinimumVersion(8, 0) && GetTablespace() != GetDatabase()->GetDefaultTablespace())
-        sql += wxT("\n  USING INDEX TABLESPACE ") + qtIdent(GetTablespace());
-
     if (GetConnection()->BackendMinimumVersion(8, 2) && GetFillFactor().Length() > 0)
         sql += wxT("\n  WITH (FILLFACTOR=") + GetFillFactor() + wxT(")");
 
+    if (GetConnection()->BackendMinimumVersion(8, 0) && GetTablespace() != GetDatabase()->GetDefaultTablespace())
+        sql += wxT("\n  USING INDEX TABLESPACE ") + qtIdent(GetTablespace());
+
     if (GetConstraint().Length() > 0)
         sql += wxT(" WHERE (") + GetConstraint() + wxT(")");
 
-- 
1.7.3.1

-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to