Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: syntax erro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 15682 of 17437
Post > Topic >>

Re: syntax error with execute

by singh.gurjeet@[EMAIL PROTECTED] ("Gurjeet Singh") May 31, 2008 at 02:46 AM

------=_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 &lt;<a
href="mailto:gentosaker@[EMAIL PROTECTED]
">gentosaker@[EMAIL PROTECTED]
>&gt;
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 &#39;INSERT INTO &#39;||tablename||&#39; (&#39;||fields||&#39;)
VALUES<br>
(&#39;||vals||&#39;) RETURNING
currval(&#39;&#39;&#39;||seqname||&#39;&#39;&#39;) INTO newid&#39;<br>
<br>
and I get the response:<br>
<br>
ERROR: &nbsp;syntax error at or near &quot;INTO&quot;<br>
LINE 1: ...&#39;,&#39;2008&#39;,&#39;4&#39;,NULL) RETURNING
currval(&#39;id_seq&#39;) 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&#39;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 &#39;INSERT INTO &#39;||tablename||&#39;
(&#39;||fields||&#39;) VALUES<br>
(&#39;||vals||&#39;) RETURNING
currval(&#39;&#39;&#39;||seqname||&#39;&#39;&#39;)&#39; 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--
 




 1 Posts in Topic:
Re: syntax error with execute
singh.gurjeet@[EMAIL PROT  2008-05-31 02:46:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 12:00:06 CST 2008.