【发布时间】:2012-08-07 04:46:36
【问题描述】:
我正在 PL/pgSQL 中编写一个函数,我正在寻找检查行是否存在的最简单方法。
现在我正在选择一个integer 到一个boolean,这并没有真正起作用。我对 PL/pgSQL 的经验还不够,还不知道最好的方法。
这是我的部分功能:
DECLARE person_exists boolean;
BEGIN
person_exists := FALSE;
SELECT "person_id" INTO person_exists
FROM "people" p
WHERE p.person_id = my_person_id
LIMIT 1;
IF person_exists THEN
-- Do something
END IF;
END; $$ LANGUAGE plpgsql;
更新 - 我现在正在做这样的事情:
DECLARE person_exists integer;
BEGIN
person_exists := 0;
SELECT count("person_id") INTO person_exists
FROM "people" p
WHERE p.person_id = my_person_id
LIMIT 1;
IF person_exists < 1 THEN
-- Do something
END IF;
【问题讨论】:
标签: sql postgresql plpgsql postgresql-9.1 exists