fix: filtering pg_attribute only by attname can return the wrong attnum if the column name exists in multiple table (#10013)

This commit is contained in:
Murtuza Zabuawala
2026-06-07 18:47:39 +05:30
committed by GitHub
parent 291a55ec5a
commit c7d2106462
3 changed files with 21 additions and 9 deletions
@@ -112,8 +112,11 @@ def create_column(server, db_name, schema_name, table_name, col_name,
connection.commit()
# Get column position of newly added column
pg_cursor.execute(
"select attnum from pg_catalog.pg_attribute where attname=%s",
(col_name,)
"SELECT a.attnum FROM pg_catalog.pg_attribute a "
"JOIN pg_catalog.pg_class c ON c.oid = a.attrelid "
"JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
"WHERE n.nspname=%s AND c.relname=%s AND a.attname=%s",
(schema_name, table_name, col_name,)
)
col = pg_cursor.fetchone()
col_pos = ''
@@ -163,8 +166,11 @@ def create_identity_column(server, db_name, schema_name, table_name,
connection.commit()
# Get column position of newly added column
pg_cursor.execute(
"select attnum from pg_catalog.pg_attribute where attname=%s",
(col_name,)
"SELECT a.attnum FROM pg_catalog.pg_attribute a "
"JOIN pg_catalog.pg_class c ON c.oid = a.attrelid "
"JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
"WHERE n.nspname=%s AND c.relname=%s AND a.attname=%s",
(schema_name, table_name, col_name,)
)
col = pg_cursor.fetchone()
col_pos = ''
@@ -112,8 +112,11 @@ def create_column(server, db_name, schema_name, table_name, col_name,
connection.commit()
# Get column position of newly added column
pg_cursor.execute(
"select attnum from pg_catalog.pg_attribute where attname=%s",
(col_name,)
"SELECT a.attnum FROM pg_catalog.pg_attribute a "
"JOIN pg_catalog.pg_class c ON c.oid = a.attrelid "
"JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
"WHERE n.nspname=%s AND c.relname=%s AND a.attname=%s",
(schema_name, table_name, col_name,)
)
col = pg_cursor.fetchone()
col_pos = ''
@@ -163,8 +166,11 @@ def create_identity_column(server, db_name, schema_name, table_name,
connection.commit()
# Get column position of newly added column
pg_cursor.execute(
"select attnum from pg_catalog.pg_attribute where attname=%s",
(col_name,)
"SELECT a.attnum FROM pg_catalog.pg_attribute a "
"JOIN pg_catalog.pg_class c ON c.oid = a.attrelid "
"JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
"WHERE n.nspname=%s AND c.relname=%s AND a.attname=%s",
(schema_name, table_name, col_name,)
)
col = pg_cursor.fetchone()
col_pos = ''
+1 -1
View File
@@ -699,7 +699,7 @@ def terminate_session(sid=None, did=None, pid=None):
@check_precondition
def check_system_statistics(sid=None, did=None):
sql = (
"SELECT * FROM pg_catalog.pg_extension "
"SELECT 1 FROM pg_catalog.pg_extension "
"WHERE extname = 'system_stats';"
)
status, res = g.conn.execute_scalar(sql)