From: | Rod Taylor <pg(at)rbt(dot)ca> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: ALTER TABLE modifications |
Date: | 2003-11-12 19:23:25 |
Message-ID: | 1068665004.30452.32.camel@jester |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
On Wed, 2003-11-12 at 14:02, Peter Eisentraut wrote:
> Rod Taylor writes:
>
> > ALTER TABLE tab ADD COLUMN col DEFAULT 3, ADD CHECK (anothercol > 3);
> I think it's perfectly fine to write two separate ALTER TABLE statements.
> No need to introduce this nonstandard syntax.
Yes, it is certainly fine to do so, but much faster to do the above.
The command shown executes nearly 40% faster than 2 independent
statements in a single transaction -- the difference is even more
significant with additional sub-commands.
> > ALTER TABLE tab ALTER COLUMN col TYPE text TRANSFORM ...;
> > Currently migrates indexes, check constraints, defaults, and the
> > column definition to the new type with optional transform. If
> > the tranform is not supplied, a standard assignment cast is
> > attempted.
>
> Please don't use the term "transform". It is used by the SQL standard for
> other purposes. What kind of object would you put in place of the "..."
> anyway? A function? What syntax do other databases use?
I've not found another database which allows this syntax. The suggestion
of TRANSFORM was Toms and was a result of using an assignment cast by
default. Do you have a better term I can use?
The ... is an A_Expr which does not accept (among other things)
subselects. CASE statements, equations, etc. work fine.
CREATE TABLE tab (col int2);
-- integer to boolean
ALTER TABLE tab ALTER col TYPE boolean
TRANSFORM CASE WHEN col >= 1 THEN true ELSE false END;
-- or say Bytes to MBytes (original column is int8)
ALTER TABLE tab ALTER col TYPE integer TRANSFORM col / (1024 * 1024);
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2003-11-12 20:30:00 | Re: [HACKERS] Proposal for a cascaded master-slave replication system |
Previous Message | Peter Eisentraut | 2003-11-12 19:02:20 | Re: ALTER TABLE modifications |
From | Date | Subject | |
---|---|---|---|
Next Message | Gaetano Mendola | 2003-11-12 23:47:09 | Re: equal() perf tweak |
Previous Message | Peter Eisentraut | 2003-11-12 19:02:20 | Re: ALTER TABLE modifications |