Обсуждение: EXECUTE plpgsql

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

EXECUTE plpgsql

От
Julio Leyva
Дата:
Hi all

I'm trying to get the next value from a sequence using a store procedure like this

create or replace function givemenext()  returns integer AS $$
DECLARE
newvalue integer;
getseq varchar(256);
BEGIN
return EXECUTE 'SELECT nextval(''test_id_seq'')';
END;
$$ language plpgsql

So when I do select * from givemenext()

I got this error message


ERROR:  type "execute" does not exist
CONTEXT:  SQL statement "SELECT  EXECUTE 'SELECT nextval(''test_id_seq'')'"
PL/pgSQL function "givemenext" line 11 at return


What I'm doing wrong?

Thanks in advance



Re: EXECUTE plpgsql

От
Tom Lane
Дата:
Julio Leyva <jcleyva@hotmail.com> writes:
> Hi allI'm trying to get the next value from a sequence using a store proced=
> ure like thiscreate or replace function givemenext()  returns integer AS $$=
> DECLAREnewvalue integer;getseq varchar(256);BEGINreturn EXECUTE 'SELECT nex=
> tval(''test_id_seq'')';END;$$ language plpgsqlSo when I do select * from gi=
> vemenext()I got this error messageERROR:  type "execute" does not existCONT=
> EXT:  SQL statement "SELECT  EXECUTE 'SELECT nextval(''test_id_seq'')'"PL/p=
> gSQL function "givemenext" line 11 at returnWhat I'm doing wrong?Thanks in =
> advance=

Please try to use a less broken mailer :-(

Anyway, that seems like the hard way.  Why not just

    return nextval('test_id_seq');

            regards, tom lane