79249142

Date: 2024-12-03 20:55:27
Score: 0.5
Natty:
Report link

I was able to get rows by editing the code as shown below:

def insert_into_returning():
        makePgEngine()
        sql_text = "insert into public.numeric_data_source (x_field,y_field,z_field)values(:x_field,:y_field,:z_field),(:x_field1,:y_field1,:z_field1),(:x_field2,:y_field2,:z_field2) returning x_field, y_field, z_field"
        qry =text(sql_text).bindparams(
            bindparam('x_field'),
            bindparam('y_field'),
            bindparam('z_field'),
            bindparam('x_field1'),
            bindparam('y_field1'),
            bindparam('z_field1'),
            bindparam('x_field2'),
            bindparam('y_field2'),
            bindparam('z_field2')                )
        params=({'x_field':-99,'y_field':-98,'z_field':-97,'x_field1':-98,'y_field1':-97,'z_field1':-96,'x_field2':-97,'y_field2':-96,'z_field2':-95})
        with pgEngine.connect() as con:
            con.execute(text("truncate table public.numeric_data_source"))
            #con.execute(text("create temp table temp_numeric_data_source as select x_field, y_field, z_field from public.numeric_data_source"))
            data=con.execute(qry, params)
            #data=con.execute(text("select * from temp_numeric_data_source"))
            print(data.fetchall())
            con.commit()

This seems to indicate that sqlalchemy returns the output of RETURNING for single sets of data at a time, like this:

sql_text = "insert into public.numeric_data_source (x_field,y_field,z_field)values(:x_field,:y_field,:z_field),(:x_field1,:y_field1,:z_field1),(:x_field2,:y_field2,:z_field2) returning x_field, y_field, z_field"
.....

params=({'x_field':-99,'y_field':-98,'z_field':-97,'x_field1':-98,'y_field1':-97,'z_field1':-96,'x_field2':-97,'y_field2':-96,'z_field2':-95})

I guess this is progress, but really not the direction I was hoping for. I will try the answer suggested by @ian-wilson

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @ian-wilson
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Z T Minhas