execute_values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

execute_values

Weatherby,Gerard

​Can I use pyscopy2.extras.execute_values with a prepared statement?


-- 
Gerard Weatherby| Application Architect
NMRbox | Department of Molecular Biology and Biophysics | UConn Health
263 Farmington Avenue, Farmington, CT 06030-6406
Phone: 860 679 8484
uchc.edu 
Reply | Threaded
Open this post in threaded view
|

Re: execute_values

Adrian Klaver-4
On 7/9/19 11:04 AM, Weatherby,Gerard wrote:
> ​Can I use pyscopy2.extras.execute_values with a prepared statement?

I don't think so as you cannot pass in VALUES():

cur.execute('prepare pt(integer, varchar, boolean) AS INSERT INTO
prepare_test values ($1, $2, $3)')

execute_values(cur, 'EXECUTE pt(%s)', [(2, 'test', 'f'),])

SyntaxError: wrong number of parameters for prepared statement "pt"
DETAIL:  Expected 3 parameters but got 1.


execute_batch works though:

execute_batch(cur, 'EXECUTE pt(%s, %s, %s)', [(2, 'test', 'f'), (3,
'dog', 't')])


>
>
> --
> *Gerard Weatherby*| Application Architect
> NMRbox | Department of Molecular Biology and Biophysics | UConn Health
> 263 Farmington Avenue, Farmington, CT 06030-6406
> Phone: 860 679 8484
> uchc.edu


--
Adrian Klaver
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: execute_values

Weatherby,Gerard
My insert has a "returning clause," I don't think execute batch supports that.

--
Gerard Weatherby| Application Architect
NMRbox | Department of Molecular Biology and Biophysics | UConn Health
263 Farmington Avenue, Farmington, CT 06030-6406
Phone: 860 679 8484
uchc.edu

________________________________________
From: Adrian Klaver <[hidden email]>
Sent: Tuesday, July 9, 2019 4:25 PM
To: Weatherby,Gerard; [hidden email]
Subject: Re: execute_values

On 7/9/19 11:04 AM, Weatherby,Gerard wrote:
> ​Can I use pyscopy2.extras.execute_values with a prepared statement?

I don't think so as you cannot pass in VALUES():

cur.execute('prepare pt(integer, varchar, boolean) AS INSERT INTO
prepare_test values ($1, $2, $3)')

execute_values(cur, 'EXECUTE pt(%s)', [(2, 'test', 'f'),])

SyntaxError: wrong number of parameters for prepared statement "pt"
DETAIL:  Expected 3 parameters but got 1.


execute_batch works though:

execute_batch(cur, 'EXECUTE pt(%s, %s, %s)', [(2, 'test', 'f'), (3,
'dog', 't')])


>
>
> --
> *Gerard Weatherby*| Application Architect
> NMRbox | Department of Molecular Biology and Biophysics | UConn Health
> 263 Farmington Avenue, Farmington, CT 06030-6406
> Phone: 860 679 8484
> uchc.edu


--
Adrian Klaver
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: execute_values

Adrian Klaver-4
On 7/10/19 5:09 AM, Weatherby,Gerard wrote:
> My insert has a "returning clause," I don't think execute batch supports that.

Well it will execute, it just will not return the values to you:(

What is your query and what are you doing with it?

>
> --
> Gerard Weatherby| Application Architect
> NMRbox | Department of Molecular Biology and Biophysics | UConn Health
> 263 Farmington Avenue, Farmington, CT 06030-6406
> Phone: 860 679 8484
> uchc.edu
>
> ________________________________________
> From: Adrian Klaver <[hidden email]>
> Sent: Tuesday, July 9, 2019 4:25 PM
> To: Weatherby,Gerard; [hidden email]
> Subject: Re: execute_values
>
> On 7/9/19 11:04 AM, Weatherby,Gerard wrote:
>> ​Can I use pyscopy2.extras.execute_values with a prepared statement?
>
> I don't think so as you cannot pass in VALUES():
>
> cur.execute('prepare pt(integer, varchar, boolean) AS INSERT INTO
> prepare_test values ($1, $2, $3)')
>
> execute_values(cur, 'EXECUTE pt(%s)', [(2, 'test', 'f'),])
>
> SyntaxError: wrong number of parameters for prepared statement "pt"
> DETAIL:  Expected 3 parameters but got 1.
>
>
> execute_batch works though:
>
> execute_batch(cur, 'EXECUTE pt(%s, %s, %s)', [(2, 'test', 'f'), (3,
> 'dog', 't')])
>
>
>>
>>
>> --
>> *Gerard Weatherby*| Application Architect
>> NMRbox | Department of Molecular Biology and Biophysics | UConn Health
>> 263 Farmington Avenue, Farmington, CT 06030-6406
>> Phone: 860 679 8484
>> uchc.edu
>
>
> --
> Adrian Klaver
> [hidden email]
>


--
Adrian Klaver
[hidden email]