leafo / pgmoon

A pure Lua Postgres driver for use in OpenResty & more
MIT License
391 stars 93 forks source link

returning column problem in update or insert sql #78

Closed gzliudan closed 2 years ago

gzliudan commented 5 years ago

When I run INSERT or UPDATE sql with returning some columns, the result only contains affected_rows, I cannot find returned columns in my sql. such as: update t1 set name='b' where id=1 returning id,name;

leafo commented 5 years ago

Can you share the code you're using to do this? returning definitely works with pgmoon, I use it heavily in all of my projects.

gzliudan commented 5 years ago

Sorry to trouble you, I got the reason, there is a mistake in my codes.

gzliudan commented 5 years ago

There's another problem, when I delete a non exist record in database: if my sql is: delete from t1 where id=0, then the pgmoon returns {"affected_rows":0} if my sql is: delete from t1 where id=0 returning id, then the pgmoon returns {} I expect pgmoon should returns affected_rows at any time.

leafo commented 2 years ago

I'm kinda undecided on the behavior but I think it's safer to leave it as is. returning converts the query into something that has a result set, so if you want to could the number of affected rows you will have to could the number of results.