Adding columns NOT NULL

From: Laurent ROCHE <laurent_roche(at)yahoo(dot)com>
To: pgAdmin III support <pgadmin-support(at)postgresql(dot)org>
Subject: Adding columns NOT NULL
Date: 2008-03-07 10:30:29
Message-ID: 514922.99305.qm@web34406.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

Hi,

There is a little anomaly in the way adding an extra column is treated in pgAdmin III 1.8.2.
... particularly if this is a NOT NULL column.

When adding the column my_col with a DEFAULT value, the code generated will be:
ALTER TABLE my_table ADD COLUMN my_col boolean;
ALTER TABLE my_table ALTER COLUMN my_col SET DEFAULT false;

This works fine ... as long as I don't insert columns with NOT NULL property.
In which case, I SUPPOSE it generates:
ALTER TABLE my_table ADD COLUMN my_col boolean NOT NULL;
ALTER TABLE my_table ALTER COLUMN my_col SET DEFAULT false;

This will not work, because the column is created with no default (hence no values) and does not support NULL values, hence creation fails.

** In pgAdmin, adding an extra column with NOT NULL property is impossible ! **

So I would suggest to generate the code:
ALTER TABLE my_table ADD COLUMN my_col boolean NOT NULL DEFAULT false;

Which does work !
And that allows to create a column with not NULL values, in one operation, and more importantly with the column populated.
At the moment, to perform the same operation I have to
- create the column, with NULL values.
- update the table to populate the column
- modify the column to NOT NULL
... or write my-self the ALTER TABLE statement !

Cheers,
L(at)u
The Computing Froggy

_____________________________________________________________________________
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

Responses

Browse pgadmin-support by date

  From Date Subject
Next Message Michael Eschweiler 2008-03-07 11:14:56 Complete breakdown of pgadmin when trying to connect to server or modify properties of tables of views
Previous Message Raphaël Enrici 2008-03-06 22:22:18 Re: Compiling PgAdmin 1.8.x on Debian LennyAMD64?