I am trying to create a SELECT FROM inside an IF statement inside a function. Here is what i have so far
CREATE OR REPLACE FUNCTION fn_check_marriage(partner_id INTEGER)
RETURNS VARCHAR(10) AS
$$
DECLARE
result text;
BEGIN
result := ''
IF EXISTS (SELECT partner_id_1 FROM marriages WHERE divorce_date IS NULL) THEN
result := 'True';
ELSE
result := 'False';
END IF;
RETURN result;
END;
$$
LANGUAGE 'plpgsql'
But it keeps on giving me errors, most recently "error at or near IF". Any thoughts on how to make this work if at all possible? Thanks in advance
Do a perform then check found or not:
PERFORM partner_id_1 FROM marriages WHERE divorce_date IS NULL;
IF FOUND THEN
result := 'True';
ELSE
result := 'False';
END IF;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.