Answers for "postgresql uuid column type"

0

Postgresql generate UUID

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

SELECT uuid_generate_v4();

           uuid_generate_v4
--------------------------------------
 a81bc81b-dead-4e5d-abff-90865d1e13b1
(1 row)
Code language: SQL (Structured Query Language) (sql)
Posted by: Guest on June-30-2021
0

postgres change column type to uuid

--  Ensure the UUID extension is installed.
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

--  Dropping and recreating the default column value is required because
--  the default INT value is not compatible with the new column type.
ALTER TABLE table_to_alter ALTER COLUMN table_id DROP DEFAULT, 
ALTER COLUMN table_id SET DATA TYPE UUID USING (uuid_generate_v4()), 
ALTER COLUMN table_id SET DEFAULT uuid_generate_v4();
Posted by: Guest on April-15-2021

Browse Popular Code Answers by Language