Skip to content

Commit

Permalink
use pg_sequence to suport Postgresql 10
Browse files Browse the repository at this point in the history
Postgresql dropped support for accessing _seq tables, use pg_sequence
instead
use CURRENT_SCHEMA() to be sure to access correct schema
  • Loading branch information
Ivan-SB committed Nov 21, 2017
1 parent e57a8af commit b676794
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/Horde/Db/Adapter/Postgresql/Schema.php
Expand Up @@ -1061,14 +1061,14 @@ public function resetPkSequence($table, $pk = null, $sequence = null)
if ($sequence) {
$quotedSequence = $this->quoteSequenceName($sequence);
$quotedTable = $this->quoteTableName($table);
$quotedPk = $this->quoteColumnName($pk);

$sql = sprintf('SELECT setval(%s, (SELECT COALESCE(MAX(%s) + (SELECT increment_by FROM %s), (SELECT min_value FROM %s)) FROM %s), false)',
$quotedPk = $this->quoteColumnName($pk);
$sql = sprintf('SELECT setval(%s, (SELECT COALESCE(MAX(%s) + (SELECT increment_by FROM pg_sequences where schemaname= ANY (CURRENT_SCHEMAS(false)) and sequencename=%s), (SELECT min_value FROM pg_sequences where schemaname= ANY (CURRENT_SCHEMAS(false)) and sequencename=%s)) FROM %s), false)',
$quotedSequence,
$quotedPk,
$sequence,
$sequence,
$quotedSequence,
$quotedSequence,
$quotedTable);

$this->selectValue($sql, 'Reset sequence');
} else {
if ($this->_logger) {
Expand Down

0 comments on commit b676794

Please sign in to comment.