Add thanks note and use uuid_nil()

This commit is contained in:
Adriano Caloiaro 2024-03-08 07:57:46 -07:00
parent b65c5a638f
commit 9ac2a7ae9a
No known key found for this signature in database
GPG key ID: C2BC56DE73CE3F75

View file

@ -82,7 +82,7 @@ So how do we perform upserts that account for the zero-value of our types? I've
CREATE OR REPLACE FUNCTION public.uuid_if_empty(id uuid) RETURNS uuid
LANGUAGE plpgsql
AS $$BEGIN
IF id = '00000000-0000-0000-0000-000000000000' THEN
IF id = uuid_nil() THEN
RETURN uuid_generate_v4();
ELSE
RETURN id;
@ -90,6 +90,8 @@ CREATE OR REPLACE FUNCTION public.uuid_if_empty(id uuid) RETURNS uuid
END$$;
```
> Thanks to [mariusor](https://lobste.rs/~mariusor) on lobste.rs for notifying me about `uuid_nil()`
Now in our upsert statement, we use our new function instead of the raw value passed in
```sql