postgresql - How to call a procedure as part of SQL statement using psycopg2 -
how go executing following insert using psycopg2?
insert file (name, volume) values ('foo', (select id volume volume.name='bar'));
this of course not work :
cursor.execute("insert file (name,volume) values (%s,%s)","foo","(select id volume volume.name='bar')")
select id volume volume.name='bar'
replaced call stored procedure :
lookup_vol_id('bar')
thanks
you use insert...select
form of insert
, e.g.:
insert file (name,volume) select 'foo', (select id volume volume.name='bar');
or if name
, column
columns in table, in order, can leave out column names entirely:
insert file select 'foo', (select id volume volume.name='bar');
either sql string can passed cursor.execute
(without semicolon).
as aside, looks perhaps volume
column should renamed volume_id
, since it's id
column volume
table.
Comments
Post a Comment