News for hackers. Stuff that matters.
Re:Type Constraints in 65 lines of SQL by nextaccountic on Friday February 17, 2023 @02:27PM (#34839141)
This is my pet peeve with SQL. I hope some day PostgreSQL gain support for native tagged unions.

I have saved some links about this

https://github.com/solidsnack/pg-sql-variants

https://thelyfsoshort.io/variant-types-in-postgresql-c63725f...

https://www.parsonsmatt.org/2019/03/19/sum_types_in_sql.html

https://typeable.io/blog/2019-11-21-sql-sum-types.html

Right now I think the ideal is a jsonb column (with a field that stores the tag) plus https://github.com/supabase/pg_jsonschema. But this is only usable if your language translates to/from JSON and generates json schema for you.

Rust can do this with https://serde.rs/ and https://docs.rs/schemars/latest/schemars/

There are no comments on this comment yet.