1

I am unable to create this function as I get syntax error near INTEGER in line 6. Am I missing something here?

CREATE OR REPLACE FUNCTION public.update_application_status_by_token(applicationToken integer, userId integer, newStatus data.applicationstatus)
  RETURNS BOOLEAN
  LANGUAGE sql
AS $function$
    DECLARE
      applicationId INTEGER;
    BEGIN
      SELECT id INTO applicationId FROM data.listings_applications WHERE token = applicationToken;
      INSERT INTO public.listings_applications_status(application_id, user_id, status)  VALUES (applicationId, userId, newStatus);
      UPDATE public.listings_applications SET status = newStatus WHERE token=applicationToken;
      RETURN TRUE;
      EXCEPTION WHEN OTHERS THEN
        RETURN FALSE;
    END;
$function$
2
  • change LANGUAGE sql to LANGUAGE plpgsql?.. Commented Dec 1, 2016 at 9:47
  • worked! Thanks, add your ans below so I can mark it as correct. Commented Dec 1, 2016 at 9:48

2 Answers 2

4

This is a PL/pgSQL function, so you must declare it as such.

Use

LANGUAGE plpgsql

rather than

LANGUAGE sql
Sign up to request clarification or add additional context in comments.

Comments

1

change

LANGUAGE sql

to

LANGUAGE plpgsql

to make it work. SQL DECLARE is for cursors. In your function it is plpgslq command

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.