0

I wanted to change dataType of column from UUID to int4

ALTER TABLE tableA ALTER COLUMN columnA TYPE int4(32);

But it is giving me an error.

ERROR: type modifier is not allowed for type "int4"

I tried to search on internet and found that I have to use USING but don't know how to use it.

1
  • Why do you want to do that? Commented Apr 4, 2020 at 11:44

2 Answers 2

1

You cannot really turn a UID into an int. There are just too many values, so you run the risk of collisions (which rises to 100% as the table gets bigger).

My guess is that you really want an id column on the table. If so, add a new column and remove the old one:

alter table tableA add a_id int generated always as identity,
                   drop columnA;

Note: in older versions of Postgres, you would use serial instead of int generated always as identity.

Sign up to request clarification or add additional context in comments.

Comments

0

Your 32 is syntactically treated as a modifier. Modifiers are allowed for numeric and decimal types, but not for plain ints, int4(xxx) is not a valid type in Postgres (I believe it is in mysql) int4 is just an alias for integer.

1 Comment

That is a different question. Maybe there is no (default) type coercion from UUID to integer. (IIRC UUIDs need 128 bits of storage, which is not even representable in a bigint)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.