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$
  • change LANGUAGE sql to LANGUAGE plpgsql?.. – Vao Tsun Dec 1 '16 at 9:47
  • worked! Thanks, add your ans below so I can mark it as correct. – Ahmed H. Saab Dec 1 '16 at 9:48
3

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

Use

LANGUAGE plpgsql

rather than

LANGUAGE sql
1

change

LANGUAGE sql

to

LANGUAGE plpgsql

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.