Skip site navigation (1) Skip section navigation (2)

Re: syntax error with execute

From: "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com>
To: "A B" <gentosaker(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: syntax error with execute
Date: 2008-05-30 21:16:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
On Fri, May 30, 2008 at 9:25 PM, A B <gentosaker(at)gmail(dot)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.


Best regards,
singh(dot)gurjeet(at){ gmail | hotmail | indiatimes | yahoo }.com


Mail sent from my BlackLaptop device

In response to

pgsql-general by date

Next:From: Fernando MorenoDate: 2008-05-30 21:22:32
Subject: Re: syntax error with execute
Previous:From: Vyacheslav KalininDate: 2008-05-30 21:04:52
Subject: Re: syntax error with execute

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group