umbrellio / laravel-pg-extensions

Laravel extensions for Postgres
MIT License
90 stars 18 forks source link

Postgres supports multiple insert returning ID, but Laravel doesn't support that #66

Closed kavanpancholi closed 2 years ago

kavanpancholi commented 2 years ago

When we batch insert into postgres database table, we can get an option by postgres to return all the inserted IDs.

INSERT INTO ycode_entities (name, email, created_at) VALUES [(...)]
RETURNING id

The above statement will retrieve all the Id that has been inserted in bulk. Unfortunately, there is no option to do this natively without using raw query in Laravel since insertMany() doesn't return ids or any primary key data.

Is there a way to extend this functionality using laravel-pg-extensions or by any means?

pvsaintpe commented 2 years ago

@kavanpancholi

It's interesting…

It's not urgent for you?

Can I take some time to think? or if you already have a ready-made patch, send it to me and I will merge it

kavanpancholi commented 2 years ago

Hey @pvsaintpe I had this case when I was working on a project, but for now, I've handled this using raw query and it works fine. but if we can think of a way to handle this using PDO then it would be great.

To answer your question, No, Its is not urgent for me. And I haven't thought of a way, but I guess we just need to append Returning {primaryKey} to the insert query and it should work.

pvsaintpe commented 2 years ago

@kavanpancholi

ok, we'll see, what can be done in the near future and issue a patch…

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days