by marcus_holmes · 6y ago · 0 comments
I'm writing in Go, so my structs all have empty values unless specifically initialised. This does sometimes mean that I get null uuid's (0000-000000-00000-0000) inserted into tables, which Postgres doesn't understand as null and cheerfully returns as a valid uuid. This has been my only real pain with using nulls.
I've contemplated modding the database driver to interpret nil-value uuid's as null, but that seems a little drastic. Anyone got any better ideas?
1. NULLIF(the_uuid, '0000-000000-00000-0000')
https://www.postgresql.org/docs/current/functions-conditiona...
2. on insert/update rules to rewrite the uuid (probably using NULLIF)
`database/sql` does have an interface which lets you define your own marshaling code though. Using it is very simple and would let you marshal an all-zero UUID into NULL easily enough.