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
<?phpnamespaceApp\Models;
useIlluminate\Database\Eloquent\Model;
useIlluminate\Database\Eloquent\SoftDeletes;
class Item extends Model
{
use SoftDeletes;
protected$fillable = ['code'];
}
Then an exception occuerd
Illuminate\Database\QueryException SQLSTATE[42P10]: Invalid column reference: 7 ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification (Connection: pgsql, SQL: insert into "items" ("code", "created_at", "updated_at") values (item1, 2023-04-26 12:51:09, 2023-04-26 12:51:09) on conflict ("code") do update set "code" = "excluded"."code", "updated_at" = "excluded"."updated_at").
When I wrote on conflict with where manually, it was working. So we have to insert where before do update to upsert with partial index.
DB::statement('INSERT INTO "items" ("code", "created_at", "updated_at") VALUES (\'item1\', NOW(), NOW()) ON CONFLICT ("code") WHERE deleted_at IS NULL DO UPDATE SET "code" = "excluded"."code", "updated_at" = "excluded"."updated_at"');
# = true
But in compileUpsert method In Illuminate\Database\Query\Grammars\PostgresGrammar in laravel/framework, on conflict and do update set is wrote in single line and it's not customizable.
$sql .= ' on conflict ('.$this->columnize($uniqueBy).') do update set ';
If you support this feature, I think we have to override compileUpsert in PostgresGrammar.
The text was updated successfully, but these errors were encountered:
The combination of upsert and partial index is not working.
I think this is not a bug, but it may worth to support.
Reproduction information is below.
Versions:
larave/franework: 10.9.0
tpetry/laravel-postgresql-enhanced: 0.29.0
Migration file:
Model:
Source Code (I ran it in tinker)
Then an exception occuerd
Illuminate\Database\QueryException SQLSTATE[42P10]: Invalid column reference: 7 ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification (Connection: pgsql, SQL: insert into "items" ("code", "created_at", "updated_at") values (item1, 2023-04-26 12:51:09, 2023-04-26 12:51:09) on conflict ("code") do update set "code" = "excluded"."code", "updated_at" = "excluded"."updated_at").
When I wrote
on conflict
withwhere
manually, it was working. So we have to insertwhere
beforedo update
to upsert with partial index.But in compileUpsert method In Illuminate\Database\Query\Grammars\PostgresGrammar in laravel/framework,
on conflict
anddo update set
is wrote in single line and it's not customizable.If you support this feature, I think we have to override compileUpsert in PostgresGrammar.
The text was updated successfully, but these errors were encountered: