我想創建以下函數來檢查是否存在某些東西。它應該返回true或false。我創建了一個觸發器來執行該功能。在任何地方都不起作用/語法錯誤。請幫助!PostgreSQL(SQL)如果否則那麼需要語法
CREATE FUNCTION checkForGPU() RETURNS BOOLEAN AS $approved$
BEGIN
IF EXISTS (
SELECT C.ID
FROM Components C, ComputerComponents CC, ComponentType T, Computer PC
WHERE CC.ComputerID = C.ID
AND CC.ComputerID = PC.ID
AND C.Type = T.ID
AND T.Name = 'GPU')
THEN
RETURN TRUE
ELSE THEN
RETURN FALSE
END;
$approved$ LANGUAGE plpgsql;
CREATE TRIGGER checkGPU
AFTER INSERT OR UPDATE OR DELETE ON ComputerComponents
EXECUTE PROCEDURE checkForGPU();
'ELSE THEN'是不正確的。 – 2015-04-04 16:29:05
我如何正確編寫else語句呢? – 2015-04-04 16:33:08
正確的語法,你可以看到[這裏](http://www.postgresql.org/docs/9.1/static/plpgsql-control-structures.html)。第39.6.2.2節。 – kvorobiev 2015-04-04 16:43:42