Add thanks note and use uuid_nil()
This commit is contained in:
parent
b65c5a638f
commit
9ac2a7ae9a
1 changed files with 3 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue