Declare not working in funtion using postgresql

时间:2017-08-04 12:03:34

标签: postgresql plpgsql

This is my function:

CREATE OR REPLACE FUNCTION public.func_leonard_test2(
    IN url text,
    OUT translation text)
  RETURNS text AS
$BODY$BEGIN

DECLARE tempo text;

SELECT CONCAT(translate,'=true') INTO tempo FROM seo_content WHERE name=url;    

    CASE

        WHEN tempo = 'location_town' THEN

            SET translation = 'A';

        ELSE

            SET translation = 'B';   

    END CASE;

END;$BODY$

I'm having trouble declaring tempo.

This is the output:

ERROR: invalid type name "CONCAT(translate,'=true') INTO tempo FROM seo_content WHERE name"

Even when I remove concat and I just keep translate, I get

ERROR: invalid type name "translate INTO tempo FROM seo_content WHERE name"

Thanks

1 个答案:

答案 0 :(得分:0)

try this:

CREATE OR REPLACE FUNCTION public.func_leonard_test2(
    IN url text,
    OUT translation text)
  RETURNS text AS
$BODY$

DECLARE tempo text;
BEGIN

SELECT CONCAT(translate,'=true') INTO tempo FROM seo_content WHERE "name"=url;    

    CASE

        WHEN tempo = 'location_town' THEN

            translation := 'A';

        ELSE

            translation := 'B';   

    END CASE;

END;$BODY$ language plpgsql;