pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedRemoving NOT NULL Contraint
3+ messages / 2 participants
[nested] [flat]
* Removing NOT NULL Contraint
@ 2000-05-03 16:17 Matthew <matt@ctlno.com>
2000-05-04 06:43 ` Re: Removing NOT NULL Contraint Vladimir V. Zolotych <gsmith@eurocom.od.ua>
0 siblings, 1 reply; 3+ messages in thread
From: Matthew @ 2000-05-03 16:17 UTC (permalink / raw)
To: pgsql-general@postgresql.org; pgsql-admin
I may be missing something simple here, but I have an attribute in a
table that was created as NOT NULL. I now need to remove this
constraint. I don't see a proper way to do this. I think I can update
the pg_attribute table and change attnotnull from true to false. Is
this an acceptable solution or is there a good reason that I should not
directly edit the system tables?
Maybe I'm missing something but I didn't see another way to do it other
then creating a new table, selecting into it and dropping the old table,
which seems like a lot of work for something so simple.
Thanks,
Matt
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Removing NOT NULL Contraint
2000-05-03 16:17 Removing NOT NULL Contraint Matthew <matt@ctlno.com>
@ 2000-05-04 06:43 ` Vladimir V. Zolotych <gsmith@eurocom.od.ua>
0 siblings, 0 replies; 3+ messages in thread
From: Vladimir V. Zolotych @ 2000-05-04 06:43 UTC (permalink / raw)
To: Matthew <matt@ctlno.com>; pgsql-admin
When I need to change table (e.g. adding new column or changing col attr)
I used the following:
1) dump the table: pg_dump -t my_table > my_table.out
2) edit my_table slightly (e.g. remain only COPY statement)
3) delete table my_table (also my_table's sequences if any)
4) create table as it should be
5) populate table, e.g. pgsql -e my_db < my_table.out
6) setting sequences, etc. (e.g. select setval('my_table_sequence', ...))
If you will know more convinient way, please let me now.
Matthew wrote:
> I may be missing something simple here, but I have an attribute in a
> table that was created as NOT NULL. I now need to remove this
> constraint. I don't see a proper way to do this. I think I can update
> the pg_attribute table and change attnotnull from true to false. Is
> this an acceptable solution or is there a good reason that I should not
> directly edit the system tables?
>
> Maybe I'm missing something but I didn't see another way to do it other
> then creating a new table, selecting into it and dropping the old table,
> which seems like a lot of work for something so simple.
>
> Thanks,
>
> Matt
^ permalink raw reply [nested|flat] 3+ messages in thread
* RE: Removing NOT NULL Contraint
@ 2000-05-04 13:43 Matthew <matt@ctlno.com>
0 siblings, 0 replies; 3+ messages in thread
From: Matthew @ 2000-05-04 13:43 UTC (permalink / raw)
To: pgsql-admin
I think in a lot of situations that process is necessary, but all I
wanted to do was change the not null flag from true to false.
I went ahead and test this out and it worked. All I did was:
update pg_attributes set attnotnull = 'f' where oid =
oidofnotnullcolumn;
vacuum analyze;
Everything seemed to work and I have not had any problems stem from
this.
> -----Original Message-----
> From: Vladimir V. Zolotych [SMTP:gsmith@eurocom.od.ua]
> Sent: Thursday, May 04, 2000 1:44 AM
> To: Matthew; pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] Removing NOT NULL Contraint
>
> When I need to change table (e.g. adding new column or changing col
> attr)
>
> I used the following:
> 1) dump the table: pg_dump -t my_table > my_table.out
> 2) edit my_table slightly (e.g. remain only COPY statement)
> 3) delete table my_table (also my_table's sequences if any)
> 4) create table as it should be
> 5) populate table, e.g. pgsql -e my_db < my_table.out
> 6) setting sequences, etc. (e.g. select setval('my_table_sequence',
> ...))
>
> If you will know more convinient way, please let me now.
>
> Matthew wrote:
>
> > I may be missing something simple here, but I have an attribute in a
> > table that was created as NOT NULL. I now need to remove this
> > constraint. I don't see a proper way to do this. I think I can
> update
> > the pg_attribute table and change attnotnull from true to false. Is
> > this an acceptable solution or is there a good reason that I should
> not
> > directly edit the system tables?
> >
> > Maybe I'm missing something but I didn't see another way to do it
> other
> > then creating a new table, selecting into it and dropping the old
> table,
> > which seems like a lot of work for something so simple.
> >
> > Thanks,
> >
> > Matt
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-05-04 13:43 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-05-03 16:17 Removing NOT NULL Contraint Matthew <matt@ctlno.com>
2000-05-04 06:43 ` Vladimir V. Zolotych <gsmith@eurocom.od.ua>
2000-05-04 13:43 RE: Removing NOT NULL Contraint Matthew <matt@ctlno.com>
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