pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
adding column with not null constraint
3+ messages / 3 participants
[nested] [flat]

* adding column with not null constraint
@ 2002-10-18 20:12 Vivek Khera <khera@kcilink.com>
  2002-10-18 21:57 ` Re: adding column with not null constraint mallah@trade-india.com
  2002-10-20 15:26 ` Re: adding column with not null constraint Johannes Lochmann <johannes.lochmann@chello.at>
  0 siblings, 2 replies; 3+ messages in thread

From: Vivek Khera @ 2002-10-18 20:12 UTC (permalink / raw)
  To: pgsql-sql

I'm looking to add a column to my database with not null and a default
value:

vk=> alter table msg_owner add column user_optional_fields varchar(255) NOT NULL default '';
ERROR:  Adding columns with defaults is not implemented.
        Add the column, then use ALTER TABLE SET DEFAULT.
vk=> alter table msg_owner add column user_optional_fields varchar(255) NOT NULL ;
ERROR:  Adding NOT NULL columns is not implemented.
        Add the column, then use ALTER TABLE ADD CONSTRAINT.

Ok, so we can succeed with this:

ALTER TABLE msg_owner ADD COLUMN user_optional_fields VARCHAR(255);
ALTER TABLE msg_owner ALTER user_optional_fields SET DEFAULT '';
UPDATE msg_owner SET user_optional_fields = '';

Now my problem is I cannot find any syntax for ALTER TABLE ADD
CONSTRAINT to put a NOT NULL constraint on a column.  Can someone help
me here?

I'm using Postgres 7.2.1 on FreeBSD 4.6.

Thanks.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497
AIM: vivekkhera Y!: vivek_khera   http://www.khera.org/~vivek/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: adding column with not null constraint
  2002-10-18 20:12 adding column with not null constraint Vivek Khera <khera@kcilink.com>
@ 2002-10-18 21:57 ` mallah@trade-india.com
  1 sibling, 0 replies; 3+ messages in thread

From: mallah@trade-india.com @ 2002-10-18 21:57 UTC (permalink / raw)
  To: khera@kcilink.com; +Cc: pgsql-sql


Hi Vivek,

In 7.3 there  will be a fully implemented ALTER TABLE command for making
columns null or not null.

Currently you can update 'attnotnull' of pg_attribute system catalog
for the attrelid and attname. use pg_class system catalog for getting
attrelid of a given relation.

Regds
MAllah.

> I'm looking to add a column to my database with not null and a default value:
>
> vk=> alter table msg_owner add column user_optional_fields varchar(255) NOT NULL default '';
> ERROR:  Adding columns with defaults is not implemented.
>        Add the column, then use ALTER TABLE SET DEFAULT.
> vk=> alter table msg_owner add column user_optional_fields varchar(255) NOT NULL ; ERROR:
> Adding NOT NULL columns is not implemented.
>        Add the column, then use ALTER TABLE ADD CONSTRAINT.
>
> Ok, so we can succeed with this:
>
> ALTER TABLE msg_owner ADD COLUMN user_optional_fields VARCHAR(255); ALTER TABLE msg_owner ALTER
> user_optional_fields SET DEFAULT '';
> UPDATE msg_owner SET user_optional_fields = '';
>
> Now my problem is I cannot find any syntax for ALTER TABLE ADD
> CONSTRAINT to put a NOT NULL constraint on a column.  Can someone help me here?
>
> I'm using Postgres 7.2.1 on FreeBSD 4.6.
>
> Thanks.
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Vivek Khera, Ph.D.
>         Khera Communications, Inc.
> Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497 AIM: vivekkhera Y!:
> vivek_khera   http://www.khera.org/~vivek/
>
> ---------------------------(end of broadcast)--------------------------- TIP 5: Have you
> checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html



-----------------------------------------
Get your free web based email at trade-india.com.
   "India's Leading B2B eMarketplace.!"
http://www.trade-india.com/





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: adding column with not null constraint
  2002-10-18 20:12 adding column with not null constraint Vivek Khera <khera@kcilink.com>
@ 2002-10-20 15:26 ` Johannes Lochmann <johannes.lochmann@chello.at>
  1 sibling, 0 replies; 3+ messages in thread

From: Johannes Lochmann @ 2002-10-20 15:26 UTC (permalink / raw)
  To: pgsql-sql

On Fri, 2002-10-18 at 22:12, Vivek Khera wrote:
> ALTER TABLE msg_owner ADD COLUMN user_optional_fields VARCHAR(255);
> ALTER TABLE msg_owner ALTER user_optional_fields SET DEFAULT '';
> UPDATE msg_owner SET user_optional_fields = '';
> 
> Now my problem is I cannot find any syntax for ALTER TABLE ADD
> CONSTRAINT to put a NOT NULL constraint on a column.  Can someone help
> me here?

An additional thought to what mallah@trade-india.com said:

BEGIN;

ALTER TABLE msg_owner ADD CONSTRAINT chk_msg_owner_usr_opt_flds_null
CHECK(user_optional_fields IS NOT NULL);

COMMIT;

HTH

Johannes Lochmann




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-10-20 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-10-18 20:12 adding column with not null constraint Vivek Khera <khera@kcilink.com>
2002-10-18 21:57 ` mallah@trade-india.com
2002-10-20 15:26 ` Johannes Lochmann <johannes.lochmann@chello.at>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox