Обсуждение: Is there a GoTo ?

Поиск
Список
Период
Сортировка

Is there a GoTo ?

От
İlyas Derse
Дата:
In this function I have to GOTO to a label1, but GOTO keyword is not working, can you please help me in getting the way from which I am able to jump from a particular code to label.
 Thanks...

CREATE OR REPLACE FUNCTION test(i integer) RETURNS integer AS $$
BEGIN
IF i<0 THEN 
RETURN i + 1;
ELSE GOTO label1;
END IF
<<label1>>
RETURN null;
END;
$$ LANGUAGE plpgsql;

Re: Is there a GoTo ?

От
Pavel Stehule
Дата:
Hi

čt 16. 1. 2020 v 11:53 odesílatel İlyas Derse <ilyasderse@gmail.com> napsal:
In this function I have to GOTO to a label1, but GOTO keyword is not working, can you please help me in getting the way from which I am able to jump from a particular code to label.
 Thanks...

no, plpgsql has not GOTO statement. It cannot be implemented in interpret type used by plpgsql.

Regards

Pavel
 

CREATE OR REPLACE FUNCTION test(i integer) RETURNS integer AS $$
BEGIN
IF i<0 THEN 
RETURN i + 1;
ELSE GOTO label1;
END IF
<<label1>>
RETURN null;
END;
$$ LANGUAGE plpgsql;

Re: Is there a GoTo ?

От
Adrian Klaver
Дата:
On 1/16/20 2:48 AM, İlyas Derse wrote:
> In this function I have to GOTO to a label1, but GOTO keyword is not 
> working, can you please help me in getting the way from which I am able 
> to jump from a particular code to label.
>   Thanks...
> 
> |CREATEORREPLACE FUNCTIONtest(i integer)RETURNS integer 
> AS$$BEGINIFi<0THENRETURNi 
> +1;ELSEGOTOlabel1;ENDIF<<label1>>RETURNnull;END;$$LANGUAGE plpgsql;|
> 

Are you looking for EXIT?:

https://www.postgresql.org/docs/12/plpgsql-control-structures.html#PLPGSQL-CONDITIONALS
42.6.5.2. EXIT

-- 
Adrian Klaver
adrian.klaver@aklaver.com



Re: Is there a GoTo ?

От
Justin
Дата:
Hi İlyas

As noted by other there is no GOTO

you can move the goto code  into the else statement

or move that code into a new function call and return  that function

or just return null in the else if that is all the it is doing
CREATE OR REPLACE FUNCTION test(i integer) RETURNS integer AS $$
BEGIN
IF i<0 THEN 
RETURN i + 1;
ELSE return second_test( i );
END IF
RETURN null;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION second_test(i integer) RETURNS integer AS $$ BEGIN return abs(i); END; $$ LANGUAGE plpgsql;

 I know TSQL and PL/SQL have this  but look at all the gotchas when constructing code with GOTO's



On Thu, Jan 16, 2020 at 5:53 AM İlyas Derse <ilyasderse@gmail.com> wrote:
In this function I have to GOTO to a label1, but GOTO keyword is not working, can you please help me in getting the way from which I am able to jump from a particular code to label.
 Thanks...

CREATE OR REPLACE FUNCTION test(i integer) RETURNS integer AS $$
BEGIN
IF i<0 THEN 
RETURN i + 1;
ELSE GOTO label1;
END IF
<<label1>>
RETURN null;
END;
$$ LANGUAGE plpgsql;