Thread: syntax error in a trigger. can't find it.

syntax error in a trigger. can't find it.

From
"Rhys A.D. Stewart"
Date:
Greetings,

I must be very tired, very hungry or both. I'm getting a syntax error in the last line with the 'END;' But am clearly not seeing what the error is. Any help would be appreciated. 
________________________________________
create or replace function dev.rqst_insrt()
returns trigger as 
$_$
DECLARE
lrec record;

BEGIN
select into lrec * from dev.rqst where rqst_delivery_time order by rqst_delivery_time desc limit 1;

if (lrec.rqst_delivery_time + '2.5 hours'::interval)::time > '16:40'::time  AND extract('dow' from (lrec.rqst_delivery_time + '24 hours'::interval)) in (1,2,3,4,5) THEN
 NEW.rqst_delivery_time := now() + '20 hours';
ELSE IF  (lrec.rqst_delivery_time + '2.5 hours'::interval)::time > '16:40'::time  AND extract('dow' from (lrec.rqst_delivery_time + '24 hours'::interval)) in (0,6) THEN
 NEW.rqst_delivery_time := now() + '2 days';
END if;

RETURN NEW;
END;
$_$
 
language plpgsql
____________________________________________

Regards,


Rhys
Peace & Love|Live Long & Posper

Re: syntax error in a trigger. can't find it.

From
"Rhys A.D. Stewart"
Date:
Found it, had ELSE IF instead of elsif......very from the indicated error.


On Sat, Jan 12, 2013 at 5:10 PM, Rhys A.D. Stewart <rhys.stewart@gmail.com> wrote:
Greetings,

I must be very tired, very hungry or both. I'm getting a syntax error in the last line with the 'END;' But am clearly not seeing what the error is. Any help would be appreciated. 
________________________________________
create or replace function dev.rqst_insrt()
returns trigger as 
$_$
DECLARE
lrec record;

BEGIN
select into lrec * from dev.rqst where rqst_delivery_time order by rqst_delivery_time desc limit 1;

if (lrec.rqst_delivery_time + '2.5 hours'::interval)::time > '16:40'::time  AND extract('dow' from (lrec.rqst_delivery_time + '24 hours'::interval)) in (1,2,3,4,5) THEN
 NEW.rqst_delivery_time := now() + '20 hours';
ELSE IF  (lrec.rqst_delivery_time + '2.5 hours'::interval)::time > '16:40'::time  AND extract('dow' from (lrec.rqst_delivery_time + '24 hours'::interval)) in (0,6) THEN
 NEW.rqst_delivery_time := now() + '2 days';
END if;

RETURN NEW;
END;
$_$
 
language plpgsql
____________________________________________

Regards,


Rhys
Peace & Love|Live Long & Posper

Re: syntax error in a trigger. can't find it.

From
Tom Lane
Date:
"Rhys A.D. Stewart" <rhys.stewart@gmail.com> writes:
> I must be very tired, very hungry or both. I'm getting a syntax error in
> the last line with the 'END;' But am clearly not seeing what the error is.
> Any help would be appreciated.

I think you need to change ELSE IF to ELSEIF.  As written you need two
END IF lines to match the two independent IFs.

I wonder whether we could get plpgsql's parser to be more helpful about
END-matching errors ... they're certainly easy ones to make.

            regards, tom lane