Patch for column properties - Mailing list pgadmin-hackers

From Guillaume Lelarge
Subject Patch for column properties
Date
Msg-id 45E76274.5010104@lelarge.info
Whole thread Raw
Responses Re: Patch for column properties  (Dave Page <dpage@postgresql.org>)
List pgadmin-hackers
Hi,

When someone set a default value for a column and set NOT NULL at the
same time, the query could fail if the table already contains NULL
values for this column. This patch adds an UPDATE statement to put the
DEFAULT value in this column for all NULL values (but only when you SET
NULL and SET DEFAULT the column at the same time).

I've done this patch for a friend but I don't quite like this patch
because of its behaviour. It doesn't warn the user. I think it would be
better to show a dialog telling that an UPDATE statement will be
executed because otherwise the whole action could fail.

So here are some questions :
  * do you think this patch is worth it ?
  * do I need to show a confirmation dialog ?
  * do I need to check first if there's NULL values on this column ?

Thanks.

Regards.


--
Guillaume.
<!-- http://abs.traduc.org/
      http://lfs.traduc.org/
      http://docs.postgresqlfr.org/ -->
Index: dlgColumn.cpp
===================================================================
--- dlgColumn.cpp    (révision 5962)
+++ dlgColumn.cpp    (copie de travail)
@@ -252,6 +252,17 @@

                 sql += wxT(";\n");
             }
+
+            if (txtDefault->GetValue() != column->GetDefault()
+                && !txtDefault->GetValue().IsEmpty()
+                && chkNotNull->GetValue() != column->GetNotNull()
+                && chkNotNull->GetValue())
+            {
+                sql += wxT("UPDATE ") + table->GetQuotedFullIdentifier()
+                    +  wxT("\n   SET ") + qtIdent(name) + wxT("=") + txtDefault->GetValue()
+                    +  wxT("\n   WHERE ") + qtIdent(name) + wxT(" IS NULL;\n");
+            }
+
             if (chkNotNull->GetValue() != column->GetNotNull())
             {
                 sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier()

pgadmin-hackers by date:

Previous
From: svn@pgadmin.org
Date:
Subject: SVN Commit by dpage: r5963 - in trunk/pgadmin3: . pgadmin/ctl pgadmin/dlg pgadmin/frm pgadmin/include/images pgadmin/include/schema pgadmin/include/utils pgadmin/schema pgadmin/utils
Next
From: "Hiroshi Saito"
Date:
Subject: Re: Lack in PostgreSql (8.2.x, 8.1.x, 8.0.x) and pgAdmin (1.6.x) updated builds (build service)