0

I am getting this error. Why?

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:

    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
0

1 Answer 1

2

I'm not a postgresql guy, but I'm 99% sure you can't put default inside VALUES() and also include a value there. I think you want this:

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 - you can include DEFAULT as a value or provide a value, but not both.

Sign up to request clarification or add additional context in comments.

3 Comments

Worked thanks, will accept soon. I am also not into postgresql. Straight from hell if you ask me. But we have to use this for our project at the moment.
@ErwinBrandstetter: that's what I thought at first, too. Scroll right; there are three total.
@EdCottrell: Ah, I see now, sorry. Took the liberty to remove some white space and removed my misguided comment. Well, and fixed the link to point to the current manual. 8.2 is rather outdated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.