0

Okay, for college I'm working on some SQL assignments but I can't figure out what's wrong here or whatever.. stuck at it for a couple of hours now.

So here I create a function:

CREATE OR REPLACE FUNCTION ins_notitie(pn_patient_nr VARCHAR, pn_notitie_datum DATE, pn_notitie_commentaar VARCHAR, lst_bijwerkdat DATE)
RETURNS void AS
$$
INSERT INTO patient_notitie(pn_patient_nr, pn_notitie_datum, pn_notitie_commentaar, lst_bijwerkdat)
VALUES ($1, $2, $3, $4)
$$
LANGUAGE sql;

Then I try to insert a new row:

SELECT ins_notitie('100001', now(), 'Test note', now());

Keep getting this error:

ERROR: function ins_notitie(unknown, timestamp with time zone, unknown, timestamp with time zone) does not exist
LINE 1: SELECT ins_notitie('100001', now(), 'Test note', now());
                            ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********

ERROR: function ins_notitie(unknown, timestamp with time zone, unknown, timestamp with time zone) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 8

The function does get created as I can see in the GUI of postgresql.

1 Answer 1

2

As the error says it cannot find the function with argument types you gave. now() returns a timestamp, not a date and a function accepting timestamp is not found.

You will be able to call the function with now()::date instead.

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

2 Comments

My god.... can't believe I didn't figure that out. Wow dude, you just made me a happy man!
@Nerotix: alternatively use current_date instead - that returns a date

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.