@@ -73,10 +73,14 @@ func (qb *queryBuilder) UpsertStatement(stmt UpsertStatement) (string, int, erro
7373 clause = "ON DUPLICATE KEY UPDATE"
7474 setFormat = `"%[1]s" = VALUES("%[1]s")`
7575 case PostgreSQL :
76- clause = fmt .Sprintf (
77- "ON CONFLICT ON CONSTRAINT %s DO UPDATE SET" ,
78- qb .getPgsqlOnConflictConstraint (stmt .Entity ()),
79- )
76+ var constraint string
77+ if constrainter , ok := stmt .Entity ().(PgsqlOnConflictConstrainter ); ok {
78+ constraint = constrainter .PgsqlOnConflictConstraint ()
79+ } else {
80+ constraint = "pk_" + into
81+ }
82+
83+ clause = fmt .Sprintf ("ON CONFLICT ON CONSTRAINT %s DO UPDATE SET" , constraint )
8084 setFormat = `"%[1]s" = EXCLUDED."%[1]s"`
8185 case SQLite :
8286 clause = "ON CONFLICT DO UPDATE SET"
@@ -301,14 +305,3 @@ func (qb *queryBuilder) BuildColumns(entity Entity, columns []string, excludedCo
301305
302306 return entityColumns [:len (entityColumns ):len (entityColumns )]
303307}
304-
305- // getPgsqlOnConflictConstraint returns the constraint name of the current [QueryBuilderOld]'s subject.
306- // If the subject does not implement the PgsqlOnConflictConstrainter interface, it will simply return
307- // the table name prefixed with `pk_`.
308- func (qb * queryBuilder ) getPgsqlOnConflictConstraint (entity Entity ) string {
309- if constrainter , ok := entity .(PgsqlOnConflictConstrainter ); ok {
310- return constrainter .PgsqlOnConflictConstraint ()
311- }
312-
313- return "pk_" + TableName (entity )
314- }
0 commit comments