PostgreSQL脚本错误

时间:2013-12-09 19:40:20

标签: sql postgresql

我收到此错误。为什么呢?

CREATE OR REPLACE FUNCTION factuurRegel()
RETURNS TRIGGER AS 
$$

BEGIN
INSERT INTO Factuur(factuurnr, factuurdatum, bestelnr)
VALUES ((default to_char(CURRENT_DATE ,'yyyy') || '-' || new.bestelnr), CURRENT_DATE, new.bestelnr);
RETURN NEW;
END;
$$
LANGUAGE plpgsql;

错误:

    ERROR:  syntax error at or near "default"
LINE 7: VALUES ((default to_char(CURRENT_DATE ,'yyyy') || '-' || new...
                 ^
********** Error **********

ERROR: syntax error at or near "default"
SQL state: 42601
Character: 137

1 个答案:

答案 0 :(得分:2)

我不是一个postgresql人,但我99%肯定你不能把default放在VALUES()里面并且还包含一个值。我想你想要这个:

CREATE OR REPLACE FUNCTION factuurRegel()
RETURNS TRIGGER AS 
$$

BEGIN
INSERT INTO Factuur(factuurnr, factuurdatum, bestelnr)
VALUES ((to_char(CURRENT_DATE ,'yyyy') || '-' || new.bestelnr), CURRENT_DATE, new.bestelnr);
RETURN NEW;
END;
$$
LANGUAGE plpgsql;

See here for more info - 您可以将DEFAULT包含为值提供值,但不能同时包含两者。