我对SQL非常陌生,目前正在使用Postgres执行函数。本质上,我希望函数1)首先执行查询,2)根据条件,更新指定的字段,3)返回结果。
CREATE OR REPLACE FUNCTION get_overdue()
RETURNS TABLE (
overdue boolean,
due_date DATE
)
$$
BEGIN
SELECT overdue, due_date FROM booking;
IF NOW()::DATE > due_date::date then
-- I want to execute and return the following the query result: UPDATE booking SET overdue = true WHERE (the result of the above query)
END IF;
end$$
如果我很了解逻辑,则可以在单个查询中执行此操作:
update booking
set overdue = true
where due_date < current_date
returning *;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句