Format using SQL Identifier type sequence name

The sequence functions are using string parameters so for case sensitive
sequence name we must pass a string containing double-quoting if necessary.

Closes #12194
This commit is contained in:
Cédric Krier
2023-04-08 11:24:45 +02:00
parent 4d950fc8e9
commit 0233bfe8d6
2 changed files with 10 additions and 6 deletions
@@ -417,18 +417,21 @@ class Database(DatabaseInterface):
def nextid(self, connection, table):
cursor = connection.cursor()
cursor.execute(
"SELECT NEXTVAL(pg_get_serial_sequence(%s, %s))", (table, 'id'))
"SELECT nextval(pg_get_serial_sequence(format(%s, %s), %s))",
('%I', table, 'id'))
return cursor.fetchone()[0]
def setnextid(self, connection, table, value):
cursor = connection.cursor()
cursor.execute(
"SELECT SETVAL(pg_get_serial_sequence(%s, %s), %s)",
(table, 'id', value))
"SELECT setval(pg_get_serial_sequence(format(%s, %s), %s), %s)",
('%I', table, 'id', value))
def currid(self, connection, table):
cursor = connection.cursor()
cursor.execute("SELECT pg_get_serial_sequence(%s, %s)", (table, 'id'))
cursor.execute(
"SELECT pg_get_serial_sequence(format(%s, %s), %s)",
('%I', table, 'id'))
sequence_name, = cursor.fetchone()
cursor.execute(f"SELECT last_value FROM {sequence_name}")
return cursor.fetchone()[0]
+3 -2
View File
@@ -49,7 +49,7 @@ class TableHandler(TableHandlerInterface):
def migrate_to_identity(table, column):
previous_seq_name = f"{table}_{column}_seq"
cursor.execute(
"SELECT NEXTVAL(%s)", (previous_seq_name,))
"SELECT nextval(format(%s, %s))", ('%I', previous_seq_name,))
next_val, = cursor.fetchone()
cursor.execute(
"SELECT seqincrement, seqmax, seqmin, seqcache "
@@ -75,7 +75,8 @@ class TableHandler(TableHandlerInterface):
"ADD GENERATED BY DEFAULT AS IDENTITY").format(
Identifier(table), Identifier(column)))
cursor.execute(
"SELECT pg_get_serial_sequence(%s, %s)", (table, column))
"SELECT pg_get_serial_sequence(format(%s, %s), %s)",
('%I', table, column))
serial_seq_name, = cursor.fetchone()
cursor.execute(
(f"ALTER SEQUENCE {serial_seq_name} INCREMENT BY %s "