Debugging pgsql function date error - Mailing list pgsql-general

From Rory Campbell-Lange
Subject Debugging pgsql function date error
Date
Msg-id 20090529003610.GA3405@campbell-lange.net
Whole thread Raw
Responses Re: Debugging pgsql function date error
List pgsql-general
I have a long plpgsql function which takes a date as one of its
arguments but I am receiving an error for another date! I'm using 8.3 on
Debian.

CREATE OR REPLACE FUNCTION
    fn_alert01_maker(integer, integer, integer, integer, date, integer)
RETURNS SETOF alert_info
AS $$
DECLARE
    userid      ALIAS for $1;
    alert       ALIAS for $2;
    since       ALIAS for $3;
    wait        ALIAS for $4;
    date_from   ALIAS for $5;
    days_until  ALIAS for $6;
    resulter    alert_info%rowtype;
    since_int   INTERVAL;
    wait_int    INTERVAL;
    days_int    INTERVAL;

BEGIN

    days_int := days_until || ' days';
    since_int := since || ' seconds';
    wait_int := wait || ' seconds';
...

and has that argument as one of its WHERE conditions:
...
        WHERE
            rs.dt_modified > ((now() - wait_int) - since_int)
            AND
            rs.d_date >= date_from
            AND
            rs.d_date <= date_from + days_int
...

Wierdly, if I call it like this, it is fine:
SELECT * FROM fn_alert01_maker(0, 1, 845, 5, '2009-05-31', 5);

But like this it throws an error:

test=> SELECT * FROM fn_alert01_maker(0, 1, 8450, 5, '2009-05-31', 5);
    ERROR:  invalid input syntax for integer: "2009-06-01"
    CONTEXT:  PL/pgSQL function "fn_alert01_maker" line 30 at FOR over
    SELECT rows


Any ideas?

Rory

pgsql-general by date:

Previous
From: Douglas Alan
Date:
Subject: Re: What is the right way to deal with a table with rows that are not in a random order?
Next
From: Alan McKay
Date:
Subject: Re: Please remove me from the list!