Hi,

I noticed that altering sequences still uses the old ALTER TABLE
syntax.  While that's required for older versions, it's not anymore.
Attached a patch to use most up-to-date syntax for each version.  This
is based on the previous newline patch having already been applied.

Obviously this won't enable anything to work that didn't previously,
but just thought it would be nice to use more suitable syntax.

-- 
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/pgadmin/dlg/dlgSequence.cpp b/pgadmin/dlg/dlgSequence.cpp
index 39319ca..d5ae231 100644
--- a/pgadmin/dlg/dlgSequence.cpp
+++ b/pgadmin/dlg/dlgSequence.cpp
@@ -248,13 +248,37 @@ wxString dlgSequence::GetSql()
 
 		if (GetName() != sequence->GetName())
 		{
-			sql += wxT("ALTER TABLE ") + sequence->GetQuotedFullIdentifier()
-			       +  wxT("\n  RENAME TO ") + qtIdent(name) + wxT(";\n");
+			if (connection->BackendMinimumVersion(8, 3))
+			{
+				sql += wxT("ALTER SEQUENCE ") + sequence->GetQuotedFullIdentifier()
+				       +  wxT("\n  RENAME TO ") + qtIdent(name) + wxT(";\n");
+			}
+			else
+			{
+				sql += wxT("ALTER TABLE ") + sequence->GetQuotedFullIdentifier()
+				       +  wxT("\n  RENAME TO ") + qtIdent(name) + wxT(";\n");
+			}
 		}
 		if (sequence->GetOwner() != cbOwner->GetValue())
 		{
-			sql += wxT("ALTER TABLE ") + schema->GetQuotedPrefix() + qtIdent(name)
-			       +  wxT("\n  OWNER TO ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+			if (connection->BackendMinimumVersion(8, 2))
+			{
+				sql += wxT("ALTER SEQUENCE ") + schema->GetQuotedPrefix() + qtIdent(name);
+
+				if (connection->BackendMinimumVersion(8, 4))
+				{
+					sql += wxT("\n  OWNER TO ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+				}
+				else
+				{
+					sql += wxT("\n  OWNED BY ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+				}
+			}
+			else
+			{
+				sql += wxT("ALTER TABLE ") + schema->GetQuotedPrefix() + qtIdent(name)
+				       +  wxT("\n  OWNER TO ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+			}
 		}
 
 		// This is where things get hairy. Per some thought by Horvath Gabor,
@@ -341,8 +365,24 @@ wxString dlgSequence::GetSql()
 		sql += wxT(";\n");
 		if (cbOwner->GetGuessedSelection() > 0)
 		{
-			sql += wxT("ALTER TABLE ")  + schema->GetQuotedPrefix() + qtIdent(name)
-			       +  wxT("\n  OWNER TO ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+			if (connection->BackendMinimumVersion(8, 2))
+			{
+				sql += wxT("ALTER SEQUENCE ") + schema->GetQuotedPrefix() + qtIdent(name);
+
+				if (connection->BackendMinimumVersion(8, 4))
+				{
+					sql += wxT("\n  OWNER TO ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+				}
+				else
+				{
+					sql += wxT("\n  OWNED BY ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+				}
+			}
+			else
+			{
+				sql += wxT("ALTER TABLE ") + schema->GetQuotedPrefix() + qtIdent(name)
+				       +  wxT("\n  OWNER TO ") + qtIdent(cbOwner->GetValue()) + wxT(";\n");
+			}
 		}
 	}
 
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to