| From: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
|---|---|
| To: | aurora <aurora00(at)gmail(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Unexpected SQL error for UPDATE |
| Date: | 2006-07-12 12:18:30 |
| Message-ID: | 793EC6C5-19C6-490F-812A-AD9FD0070107@seespotcode.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Jul 11, 2006, at 20:47 , aurora wrote:
> There is no simple SQL to alter the type. So I use a series of SQLs to
> create a new column, copy the data over and then replace the old
> column with the
> new.
What version of PostgreSQL are you running? In 8.0 and later you can
use ALTER TABLE ALTER TYPE.
http://www.postgresql.org/docs/current/interactive/sql-altertable.html
Something like this (untested) should work in your case:
ALTER TABLE users ALTER email_addresses TYPE text;
> ALTER TABLE users ADD email_address_text text UNIQUE;
> UPDATE users set email_address_text=email_address;
> ALTER TABLE users DROP email_address;
> ALTER TABLE users RENAME email_address_text TO email_address;
> ALTER TABLE users ALTER email_address SET not null;
This looks like it should work, so perhaps someone else has an idea
as to why you're receiving the error. Is the error reproducible? If
you can put together a reproducible test case, it may help someone
else be able to figure out what's going on.
Michael Glaesemann
grzm seespotcode net
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jaime Casanova | 2006-07-12 13:12:21 | Re: Unexpected SQL error for UPDATE |
| Previous Message | Exner, Peter | 2006-07-12 08:06:34 | Re: How to find entries missing in 2nd table? |