1

In my vault_log table there is a column resp_id, the data type is varchar(40) and I want to alter the data type from varchar(40) to uuid but I get this error when trying to do so:

ERROR: invalid input syntax for type UUID:

This is the command I have used:

alter table vault_log 
    alter column resp_id type uuid using resp_id::uuid; 

Table schema:

Column Type Collation Nullable Default
ac character varying(20) not null
scheme_code character varying(20) not null
req_ts timestamp without time zone not null
res_ts timestamp without time zone not null
resp character varying(20) not null
err character varying(20)
resp_id character varying(40) not null
txn uuid not null
client_ip character varying(20)
opr character varying(20) not null
vault_id integer not null nextval('vault_log_vault_id_seq'::regclass)
mac_id character varying
1
  • 1
    An empty string is not a valid UUID. Use NULL when there is no valid UUID, but you have to drop the current NOT NULL constraint. Commented May 26, 2022 at 9:29

1 Answer 1

0

It should work.
demo
If not working means resp_id column stored some value(s) in it.
Obvious, everything can be cast to text. further info, see pg_cast

( SELECT DISTINCT
        typname
    FROM
        pg_cast c
        JOIN pg_type t ON c.casttarget = t.oid
    WHERE
        typname ILIKE '%uuid%')
UNION ALL ( SELECT DISTINCT
        typname
    FROM
        pg_cast c
        JOIN pg_type t ON c.castsource = t.oid
    WHERE
        typname ILIKE '%uuid%');

return zero rows.
zero rows means: There is no explicit cast to and from data type uuid.
So you should just add an new uuid column.

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

Comments

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.