我有一个PostgreSQL存储过程,它包含以下代码:
IF something = TRUE THEN
SELECT id INTO some_id FROM some_table WHERE some conditions LIMIT 1;
RETURN QUERY SELECT * FROM some_table WHERE some conditions LIMIT 1;
ELSE
SELECT id INTO some_id FROM some_table WHERE some OTHER conditions LIMIT 1;
RETURN QUERY SELECT * FROM some_table WHERE some OTHER conditions LIMIT 1;
END IF;
DELETE FROM some_table where id = some_id;有办法简化上面的代码吗?我想我们对IF和ELSE中的重复代码无能为力,但是有什么方法可以避免每次使用2SELECT吗?在some_id中是否可以在RETURN QUERY中插入一些东西?
发布于 2014-09-25 14:14:01
如果该函数只执行您发布的内容,则没有必要:
delete from some_table
where
something and (some conditions)
or
something is not true and (some other conditions)
returning *https://stackoverflow.com/questions/26040672
复制相似问题