pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedChanging column modifiers?
4+ messages / 4 participants
[nested] [flat]
* Changing column modifiers?
@ 2001-09-10 01:08 Tim Boring <tboring@insight.rr.com>
0 siblings, 2 replies; 4+ messages in thread
From: Tim Boring @ 2001-09-10 01:08 UTC (permalink / raw)
To: pgsql-admin
Can you change a column modifier after you've created the table? For
example, I have a table called "authors" with the following columns:
authorid, authorfirstname, authorlastname, authormi, statecode, country,
born, deceased.
When I created the table, I forgot to make the "authorfirstname" and
"authorlastname" columns NOT NULL. I've looked at ALTER TABLE but I
don't see a way to use it to add NOT NULL...maybe I'm just missing the
obvious?
Any help/suggestions are appreciated.
Thanks,
Tim
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Changing column modifiers?
@ 2001-09-10 09:06 Arne Weiner <aswr@gmx.de>
parent: Tim Boring <tboring@insight.rr.com>
1 sibling, 0 replies; 4+ messages in thread
From: Arne Weiner @ 2001-09-10 09:06 UTC (permalink / raw)
To: pgsql-admin
It seems that it is not possible to alter column constraints and
table constraints do not include NOT NUL.
But you can use CHECK as workaround:
ALTER TABLE authors ADD CHECK (NOT authorfirstname = NULL);
Arne.
Tim Boring wrote:
>
> Can you change a column modifier after you've created the table? For
> example, I have a table called "authors" with the following columns:
> authorid, authorfirstname, authorlastname, authormi, statecode, country,
> born, deceased.
>
> When I created the table, I forgot to make the "authorfirstname" and
> "authorlastname" columns NOT NULL. I've looked at ALTER TABLE but I
> don't see a way to use it to add NOT NULL...maybe I'm just missing the
> obvious?
>
> Any help/suggestions are appreciated.
>
> Thanks,
> Tim
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Changing column modifiers?
@ 2001-09-11 00:27 Lee Harr <missive@frontiernet.net>
parent: Tim Boring <tboring@insight.rr.com>
1 sibling, 0 replies; 4+ messages in thread
From: missive@frontiernet.net @ 2001-09-11 00:27 UTC (permalink / raw)
To: pgsql-admin
On Mon, 10 Sep 2001 01:25:59 +0000 (UTC), Tim Boring <tboring@insight.rr.com>:
> Can you change a column modifier after you've created the table? For
> example, I have a table called "authors" with the following columns:
> authorid, authorfirstname, authorlastname, authormi, statecode, country,
> born, deceased.
>
> When I created the table, I forgot to make the "authorfirstname" and
> "authorlastname" columns NOT NULL. I've looked at ALTER TABLE but I
> don't see a way to use it to add NOT NULL...maybe I'm just missing the
> obvious?
>
How about creating a new table as you like it, then
selecting the data from the old table into the new one
dropping the old table and renaming the new one?
Roundabout, but might be useful.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Changing column modifiers?
@ 2001-09-11 08:47 Henshall, Stuart - WCP <SHenshall@westcountrypublications.co.uk>
0 siblings, 0 replies; 4+ messages in thread
From: Henshall, Stuart - WCP @ 2001-09-11 08:47 UTC (permalink / raw)
To: 'Arne Weiner' <aswr@gmx.de>; pgsql-admin
ALTER TABLE authors ADD CHECK (NOT authorfirstname = NULL);
Should that be:
ALTER TABLE authors ADD CHECK (NOT authorfirstname IS NULL);
?
Anyway, how about something like the following:
UPDATE pg_attribute SET attnotnull='t' WHERE attname='field_name' AND
attrelid in (SELECT pg_class.oid FROM pg_class WHERE relkind='r' AND
relname='table_name');
Where field_name is the field name and table_name is the table name.
Hope this helps,
- Stuart
> -----Original Message-----
> From: Arne Weiner [SMTP:aswr@gmx.de]
> Sent: Monday, September 10, 2001 10:06 AM
> To: pgsql-admin@postgresql.org
> Subject: Re: Changing column modifiers?
>
>
> It seems that it is not possible to alter column constraints and
> table constraints do not include NOT NUL.
> But you can use CHECK as workaround:
>
> ALTER TABLE authors ADD CHECK (NOT authorfirstname = NULL);
>
> Arne.
>
> Tim Boring wrote:
> >
> > Can you change a column modifier after you've created the table? For
> > example, I have a table called "authors" with the following columns:
> > authorid, authorfirstname, authorlastname, authormi, statecode, country,
> > born, deceased.
> >
> > When I created the table, I forgot to make the "authorfirstname" and
> > "authorlastname" columns NOT NULL. I've looked at ALTER TABLE but I
> > don't see a way to use it to add NOT NULL...maybe I'm just missing the
> > obvious?
> >
> > Any help/suggestions are appreciated.
> >
> > Thanks,
> > Tim
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/users-lounge/docs/faq.html
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-09-11 08:47 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-09-10 01:08 Changing column modifiers? Tim Boring <tboring@insight.rr.com>
2001-09-10 09:06 ` Arne Weiner <aswr@gmx.de>
2001-09-11 00:27 ` Lee Harr <missive@frontiernet.net>
2001-09-11 08:47 Re: Changing column modifiers? Henshall, Stuart - WCP <SHenshall@westcountrypublications.co.uk>
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