Re: Newbie ...Function error (Stored Procedure)?

Поиск
Список
Период
Сортировка
От Richard Poole
Тема Re: Newbie ...Function error (Stored Procedure)?
Дата
Msg-id 20010831184210.I24593@office.vi.net
обсуждение исходный текст
Ответ на Newbie ...Function error (Stored Procedure)?  (zhi7c001@sneakemail.com (Ron S))
Список pgsql-general
On Mon, Aug 27, 2001 at 12:34:14PM -0700, Ron S wrote:
> I have a sequence called seq1.
>
> In psql I am trying to create a function which simply calls this
> sequence with the nextval() function.
>
> CREATE FUNCTION testid()
> RETURNS INTEGER
> AS 'SELECT NEXTVAL('seq1');'
> LANGUAGE 'SQL';
>
>
> I get the following error....
> ERROR:  parser: parser error at or near "seq1"
>
> I can call nextval('seq1') by itself with now error.
>
> What am I doing wrong?

The first single quote after the left parenthesis is seen as ending
the function body, so postgres looks for the keyword LANGUAGE
immediately afterwards. Double your single quotes inside the function
body or backslash them:

CREATE FUNCTION testid()
RETURNS INTEGER
AS 'SELECT NEXTVAL(''seq1'');'
LANGUAGE 'SQL';

or

CREATE FUNCTION testid()
RETURNS INTEGER
AS 'SELECT NEXTVAL(\'seq1\');'
LANGUAGE 'SQL';

Richard

В списке pgsql-general по дате отправления:

Предыдущее
От: "Mikheev, Vadim"
Дата:
Сообщение: Re: Deployment of PostgreSQL Applications
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Deployment of PostgreSQL Applications