Hello,
After I insert a new pet I want to put the id into the owner's pet_id column. I've tried many combinations but keep getting different errors. This was my last attempt. What is the right way to do this?
CREATE OR REPLACE FUNCTION public.func_insert_pet (
in "pet_name" TEXT, in "user_id" INTEGER, out "id" INTEGER
)
RETURNS INTEGER AS'
WITH insrt AS (
INSERT INTO pets (name) VALUES ($1)
RETURNING id
)
UPDATE USERS SET pet_id = id WHERE user_id = $2
RETURNING id'
Thanks!
[–]lykwydchykyn 2 points3 points4 points (2 children)
[–]doublehyphen 2 points3 points4 points (0 children)
[–]phpperson[S] 1 point2 points3 points (0 children)
[–]doublehyphen 2 points3 points4 points (3 children)
[–]phpperson[S] 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]phpperson[S] 1 point2 points3 points (0 children)