Goal: We want to pass current_user.id (or any other dynamic value) in a condition query.
Steps: -->
DO $$
DECLARE v_USERID INT := {{ current_user.id }};
DECLARE v_Message VARCHAR(100);
BEGIN
-- Conditional logic
IF v_USERID > 0 THEN
v_Message := 'User id found;
ELSE
v_Message := 'User id not found';
END IF;
RAISE NOTICE '%', v_Message;
END $$;
It gives following error:
bind message supplies 1 parameters, but prepared statement "" requires 0
But if pass it in a simple query like following, it works fine.
SELECT * from TABLE_NAME where user_id = {{ current_user.id }};