Re: Function Syntax Help

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dennis Ryan <dennis(at)kabonkulator(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function Syntax Help
Date: 2014-06-26 16:27:41
Message-ID: CAFj8pRAeWkr13tK6BNBHr_3FoSbvkFzLHBdH=0exG2sOEHC5FA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

You are using PLpgSQL CASE statement

this start by CASE keyword and finishing by END CASE keywords

CREATE OR REPLACE FUNCTION sn_dm_b.pm_insert_trigger()
RETURNS TRIGGER AS $$
BEGIN
CASE
WHEN NEW.period = 201001
THEN INSERT INTO sn_dm_b.pm201001 VALUES (NEW.*);
END;
RETURN NULL;
END CASE; -- <<<<<<<<<<<<<
$$ LANGUAGE plpgsql;

2014-06-26 0:19 GMT+02:00 Dennis Ryan <dennis(at)kabonkulator(dot)com>:

> I having trouble with correct syntax to get this trigger function to
> compile. I have tried every combination of removing the ‘;’ characters but
> the function will not compile. Can someone tell me what I am doing wrong,
> I am stumped. I will be adding addition when clauses the case statement
> once I get this simplified version to compile.
>
> I am using 9.3.4, both postgres and psql.
>
>
> CREATE OR REPLACE FUNCTION sn_dm_b.pm_insert_trigger()
> RETURNS TRIGGER AS $$
> BEGIN
> CASE
> WHEN NEW.period = 201001
> THEN INSERT INTO sn_dm_b.pm201001 VALUES (NEW.*);
> END;
> RETURN NULL;
> END;
> $$ LANGUAGE plpgsql;
>
>
> ERROR: syntax error at or near ";"
> LINE 7: END;
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shaun Thomas 2014-06-26 16:28:28 Re: Function Syntax Help
Previous Message Raymond O'Donnell 2014-06-26 16:26:15 Re: Function Syntax Help