Re: syntax error with execute

Поиск
Список
Период
Сортировка
От Gurjeet Singh
Тема Re: syntax error with execute
Дата
Msg-id 65937bea0805301416l58b236f5rc341f4711efd187d@mail.gmail.com
обсуждение исходный текст
Ответ на syntax error with execute  ("A B" <gentosaker@gmail.com>)
Список pgsql-general
On Fri, May 30, 2008 at 9:25 PM, A B <gentosaker@gmail.com> wrote:
I have a query like this in a plpgsql function:

EXECUTE 'INSERT INTO '||tablename||' ('||fields||') VALUES
('||vals||') RETURNING currval('''||seqname||''') INTO newid'

and I get the response:

ERROR:  syntax error at or near "INTO"
LINE 1: ...','2008','4',NULL) RETURNING currval('id_seq') INTO newid

And I do not understand this error. If I take the INSERT command and
run it by hand, it works fine, but it doesn't work in the function
when called by execute. Anybody has an idea on what is wrong and what
to do about it?

The final INTO clause should be outside the string, like this:

EXECUTE 'INSERT INTO '||tablename||' ('||fields||') VALUES
('||vals||') RETURNING currval('''||seqname||''')' INTO newid

Note the placement of the last quote.

HTH,

Best regards,
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com

EnterpriseDB http://www.enterprisedb.com

Mail sent from my BlackLaptop device

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

Предыдущее
От: "Fernando Moreno"
Дата:
Сообщение: Re: syntax error with execute
Следующее
От: Brian Cox
Дата:
Сообщение: conditional alter table