I am attempting to pass arguments to the following function in Golang with db.QueryRow(), however it doesn't seem to accept the usual ?.
DROP FUNCTION IF EXISTS upsertplatform(pToken varchar); CREATE FUNCTION upsertplatform(pToken varchar) RETURNS int as $$ DECLARE _id int = NULL; BEGIN LOOP UPDATE public.platform SET platformToken = pToken WHERE userID = 3 AND platformID = 2 RETURNING id into _id; IF NOT FOUND THEN BEGIN INSERT INTO public.platform (userID, platformID, platformToken) VALUES (3, 2, '1234-123-bbasd') RETURNING id into _id; EXCEPTION WHEN unique_violation THEN UPDATE public.platform SET platformToken = '1234-123-bbasd' WHERE userID = 3 AND platformID = 2 RETURNING id into strict _id; END; END IF; EXIT WHEN _id IS NOT NULL; END LOOP; RETURN 1; END $$ LANGUAGE PLPGSQL;
This is the query I am having issues with, I'm unsure how to pass arguments to it:
res := db.QueryRow(`SELECT * FROM upsertplatform( ? )`, "test123")
How do I do this correctly?