i have table uses uuids primary keys. new rows inserted this
insert ( id, ... ) values ( uuid_generate_v4(), ...)
now want generate uuid when no id provided in insert (either null
or empty string)
is possible write this?
insert ( id, ... ) values ( $1 || uuid_generate_v4(), ...)
the coalesce() function use first non-null. if $1 null, coalesce() use uuid_generate_v4(). otherwise, try use $1.
insert (id, ... ) values (coalesce($1, uuid_generate_v4()), ... );
Comments
Post a Comment