You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Postgres and I need to submit a query like:
insert into mytable (field1, field2) values (value1, value2) ON CONFLICT DO NOTHING RETURNING id
I tried to use insertOrIgnore() method but It build the query with only ON CONFLICT DO NOTHING; I tried to use insertGetId() method but It build the query with only RETURNING id.
Is there a way to "chain" the two methods?
I also tried to build a raw insert:
DB::insert('insert into mytable (field1, field2) values (?, ?) ON CONFLICT DO NOTHING returning "id"', [
$value1,
$value2
]);
but It doesn't return the id when the record is missing; It returns only true or false.
Could It be possibile to implement a new method like:
public function compileInsertOrIgnoreAndGetId(Builder $query, $values, $sequence)
{
return $this->compileInsert($query, $values).' on conflict do nothing returning '.$this->wrap($sequence ?: 'id');
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Postgres and I need to submit a query like:
I tried to use
insertOrIgnore()
method but It build the query with onlyON CONFLICT DO NOTHING
; I tried to useinsertGetId()
method but It build the query with onlyRETURNING id
.Is there a way to "chain" the two methods?
I also tried to build a raw insert:
but It doesn't return the
id
when the record is missing; It returns onlytrue
orfalse
.Could It be possibile to implement a new method like:
into:
Thank you
Beta Was this translation helpful? Give feedback.
All reactions