0

I tried in Postgres 9.3

CREATE OR REPLACE FUNCTION f_tsd(koakuupav date, kolkuupaev date)
  RETURNS TABLE (
isikukood int
) AS
$func$
select 1 where current_date between koakuupaev and kolkuupaev
$func$ LANGUAGE sql STABLE;

but got error

ERROR:  column "koakuupaev" does not exist

In plpgsql it causes same error at run time:

CREATE OR REPLACE FUNCTION f_tsd(koakuupav date, kolkuupaev date)
  RETURNS TABLE (
isikukood int
) AS
$func$
BEGIN
RETURN QUERY  select 1 where current_date between  koakuupaev and kolkuupaev;
end; $func$ LANGUAGE plpgsql stable;

select * from f_tsd(current_date, current_date)

How to pass parameters to where clause in function in Postgres ? According to docs named parameters must work.

2
  • 1
    Which Postgres version are you using? The ability to use a named parameter inside a SQL function was added in 9.2 if I'm not mistaken. If you are on an older version, you need to use $1 and $2. But in either case you need to change the data type of the returned table to integer or cast the 1 to a numeric value (I guess that's the problem with your second version) Commented Nov 1, 2014 at 14:39
  • I'm using 9.3. According to docs named parameters must work. I changed return type to integer but problem persists Commented Nov 1, 2014 at 18:03

1 Answer 1

3

The first parameter name koakuupav is missing an e in pav in instead of paev

f_tsd(koakuupav date, kolkuupaev date)

between  koakuupaev and kolkuupaev
Sign up to request clarification or add additional context in comments.

Comments

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.