is there way to see if condition for if value is t...
# sql
j
is there way to see if condition for if value is type uuid because I have input from jsonb and have null check but then want if its not null but its also not a uuid like Basically if its not a uuid provided set it
Copy code
if (jsonb_typeof(jsonb_extract_path(child, 'id')) = 'null' or (not child->'id'::uuid)) then
        child = jsonb_set(child::jsonb,'{id}',to_jsonb(uuid_generate_v4()));
      end if;
c
I don't think PostgreSQL/SQL have anything built-in to check if a string is of type UUID but you have two relatively easy to implement options: 1) Use a regex to check if the string looks like a UUID, see: https://stackoverflow.com/questions/136505/searching-for-uuids-in-text-with-regex, https://stackoverflow.com/a/46445888/2606261 2) Create a custom stored procedure which tries to convert a string to a UUID and catches the exception in case of failure: https://stackoverflow.com/a/46433640/2606261
j
ok yeah cause i didnt know if just adding ::uuid because it errors out if there is something else provided if instead of erroring out i could do if then to correct but yeah looks like regex looks the most straightforward. Thanks!