------=_Part_4306_5840331.1212182191578
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
On Fri, May 30, 2008 at 9:25 PM, A B <gentosaker@[EMAIL PROTECTED]
> 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]@[EMAIL PROTECTED]
gmail | hotmail | indiatimes | yahoo }.com
EnterpriseDB http://www.enterprisedb.com
Mail sent from my BlackLaptop device
------=_Part_4306_5840331.1212182191578
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
On Fri, May 30, 2008 at 9:25 PM, A B <<a
href="mailto:gentosaker@[EMAIL PROTECTED]
">gentosaker@[EMAIL PROTECTED]
>>
wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt
0.8ex; padding-left: 1ex;">
I have a query like this in a plpgsql function:<br>
<br>
EXECUTE 'INSERT INTO '||tablename||' ('||fields||')
VALUES<br>
('||vals||') RETURNING
currval('''||seqname||''') INTO newid'<br>
<br>
and I get the response:<br>
<br>
ERROR: syntax error at or near "INTO"<br>
LINE 1: ...','2008','4',NULL) RETURNING
currval('id_seq') INTO newid<br>
<br>
And I do not understand this error. If I take the INSERT command and<br>
run it by hand, it works fine, but it doesn't work in the function<br>
when called by execute. Anybody has an idea on what is wrong and what<br>
to do about it?<br>
</blockquote></div><br>The final INTO clause should be outside the string,
like this:<br><br>EXECUTE 'INSERT INTO '||tablename||'
('||fields||') VALUES<br>
('||vals||') RETURNING
currval('''||seqname||''')' INTO newid<br>
<br>Note the placement of the last quote.<br><br>HTH,<br><br>Best
regards,<br>-- <br>gurjeet[.singh]@[EMAIL PROTECTED]
>singh.gurjeet@[EMAIL PROTECTED]
| hotmail | indiatimes | yahoo }.com<br><br>EnterpriseDB <a
href="http://www.enterprisedb.com">http://www.enterprisedb.com</a><br>
<br>Mail sent from my BlackLaptop device
------=_Part_4306_5840331.1212182191578--


|