From bc0cfbd589ccd9799e7079a381c11ffd1f1bf566 Mon Sep 17 00:00:00 2001
From: Timon <timosha@gmail.com>
Date: Thu, 23 Aug 2012 11:59:59 +0600
Subject: [PATCH] Fix column SQL

This avoid errors when you try to add column with not null
constraint to existing table with some data.
---
 pgadmin/schema/pgColumn.cpp |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/pgadmin/schema/pgColumn.cpp b/pgadmin/schema/pgColumn.cpp
index 49a44d6..f5bb63f 100644
--- a/pgadmin/schema/pgColumn.cpp
+++ b/pgadmin/schema/pgColumn.cpp
@@ -179,18 +179,16 @@ wxString pgColumn::GetSql(ctlTree *browser)
 				      + GetQuotedTypename();
 				if (!GetCollation().IsEmpty() && GetCollation() != wxT("pg_catalog.\"default\""))
 					sql += wxT(" COLLATE ") + GetCollation();
-				sql += wxT(";\n");
-
-				sql += GetStorageSql();
-
 				if (GetNotNull())
-					sql += wxT("ALTER TABLE ") + GetQuotedFullTable()
-					       + wxT(" ALTER COLUMN ") + GetQuotedIdentifier()
-					       + wxT(" SET NOT NULL;\n");
+					sql += wxT(" NOT NULL");
+
 				if (!GetDefault().IsEmpty())
-					sql += wxT("ALTER TABLE ") + GetQuotedFullTable()
-					       + wxT(" ALTER COLUMN ") + GetQuotedIdentifier()
-					       + wxT(" SET DEFAULT ") + GetDefault() + wxT(";\n");
+					sql += wxT(" DEFAULT ") + GetDefault();
+
+				sql += wxT(";\n\n");
+
+				sql += GetStorageSql();
+					       
 				sql += GetAttstattargetSql();
 
 				sql += GetVariablesSql();
-- 
1.7.7.6

