Sample Header Ad - 728x90

How do I add a constraint on the UUID type of Postgres to only allow UUID v4?

4 votes
1 answer
476 views
I have a lot of tables in a **Postgres 14** database that use the native UUID type. Is there a database-wide setting/constraint to limit this type to only allow UUID v4? ### A potential solution I've come across [CREATE DOMAIN](https://www.postgresql.org/docs/14/sql-createdomain.html) . I can extend the UUID type, set a CONSTRAINT to CHECK the version bit to be equal to 4. After that, I'd have to include a migration with a lot of ALTER TABLES. Is there any other way of doing this to an existing database?
Asked by Abhijit (181 rep)
Nov 23, 2022, 11:41 AM
Last activity: Jul 17, 2023, 05:14 AM