Skip to content

PostgreSQL - sequence must work on concurent mixed (/w/wo ID) inserts #714

@mvorisek

Description

@mvorisek

I think, when ID is not set, we can insert like INSERT INTO t (id, c, ...) VALUES (xx, c_val, ...)

where xx can be something like select max(id, seq.nextval) instead

// PostgreSQL sequence must be manually synchronized if a row with explicit ID was inserted
if ($this->connection instanceof \Atk4\Data\Persistence\Sql\Postgresql\Connection) {
$this->connection->expr(
'select setval([], coalesce(max({}), 0) + 1, false) from {}',
[$this->getIdSequenceName($model), $model->id_field, $model->table]
)->execute();
}

note: As PK is unique, this should throw an duplicate PK now, thus not corrupt data.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions