Postgres Altering column type using user-defined function

3922 views postgresql
1

I have a column which is stored as TEXT, I would like to change it to UUID in postgres. But I need to run some function on the column first to change it to UUID. Is it possible to do smth like that?

ALTER TABLE am.product ALTER COLUMN p_merchant_id TYPE UUID USING myFunc;

Where myFunc returns UUID with the input merchant_id?

answered question

1 Answer

13

Yes, that's possible.

You just need to pass the old value to your function:

ALTER TABLE am.product 
   ALTER COLUMN p_merchant_id TYPE UUID USING myfunc(p_merchant_id);

posted this

Have an answer?

JD

Please login first before posting an answer.