I am trying to insert user and multiple of his user role + return id of created user in single row. I used following query:
WITH inserted_user as ( insert into "user" (username, password, nickname, account_non_expired, account_non_locked, credentials_non_expired, enabled) values ('username', 'password-hash', 'nickanme', true, true, true, true) returning id ) insert into user_role values ((select id from inserted_user), 2), ((select id from inserted_user), 3), ((select id from inserted_user), 4) returning user_id;
My issue is, that in my result I see 3 rows with the same ID (this is bad for my java application which expects 1 number). I am not sure how to edit this to get my result. I tried to wrap this into another select + many other more or less dumb things, but none of it was working. Could you please help me?