supabase-py icon indicating copy to clipboard operation
supabase-py copied to clipboard

Can't retrieve select() after insert()

Open plbeaudoin opened this issue 2 years ago • 2 comments

Describe the bug As per documentation (of the other official APIs), we should be calling .select() after an insert() to retrieve the inserted row's id. Unfortunately, .select() does not exist on SyncQueryRequestBuilder, and simply calling insert does not return the inserted row.

To Reproduce supabase.table("Test").insert(vars(test)).select('id').execute() AttributeError: 'SyncQueryRequestBuilder' object has no attribute 'select'

Expected behavior The id is returned.

Desktop:

  • Python 3.9
  • Supabase-py 1.0.2

plbeaudoin avatar Apr 05 '23 17:04 plbeaudoin

Data is returned anyway from execute. Data is based on the returning param of insert, but defaults to full representation.

resp = supabase.table("table").insert(data, upsert=True).execute()
obj = resp.data[0] # full json object of row

You can change returning to "minimal," though I haven't tested it so not sure if it gives you only a primary key or not.

ericmillsio avatar Jun 26 '23 13:06 ericmillsio

Tried setting returning to "minimal" and it just returned an empty list, even though the rows get inserted.

billkabanga avatar Nov 16 '23 21:11 billkabanga

The documentation has since been updated. You don't call .select() after .insert() for the Python library. We will probably change to follow the JavaScript library in the next major version release.

silentworks avatar Apr 28 '24 22:04 silentworks