Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3.Row class, handling duplicate column names resulting from a SQL join #49355

Closed
sockonafish mannequin opened this issue Jan 29, 2009 · 4 comments
Closed

sqlite3.Row class, handling duplicate column names resulting from a SQL join #49355

sockonafish mannequin opened this issue Jan 29, 2009 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sockonafish
Copy link
Mannequin

sockonafish mannequin commented Jan 29, 2009

BPO 5105

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-02-05.14:16:46.926>
created_at = <Date 2009-01-29.23:53:29.911>
labels = ['type-bug', 'library']
title = 'sqlite3.Row class, handling duplicate column names resulting from a SQL join'
updated_at = <Date 2009-02-05.14:16:46.925>
user = 'https://bugs.python.org/sockonafish'

bugs.python.org fields:

activity = <Date 2009-02-05.14:16:46.925>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2009-02-05.14:16:46.926>
closer = 'georg.brandl'
components = ['Library (Lib)']
creation = <Date 2009-01-29.23:53:29.911>
creator = 'sockonafish'
dependencies = []
files = []
hgrepos = []
issue_num = 5105
keywords = []
message_count = 4.0
messages = ['80798', '80847', '80849', '80853']
nosy_count = 2.0
nosy_names = ['ggenellina', 'sockonafish']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5105'
versions = ['Python 2.6']

@sockonafish
Copy link
Mannequin Author

sockonafish mannequin commented Jan 29, 2009

When using sqlite3.Row as the row_factory for a sqlite3 connection and
performing a SQL join that returns rows from two or more tables with
identical column names, the returned sqlite3.Row object contains
duplicate keys. Subsequently, when trying to access values by key, only
the value contained in the lowest numbered index matching the key is
returned. Additionally, attempting to use the keys returned to create a
new table in the database fails due to a duplicate column name error.

A better behavior would be for the sqlite3.Row object's indices to be
prefixed with table names for cases in which a query produces results
from two or more tables.

@sockonafish sockonafish mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 29, 2009
@ggenellina
Copy link
Mannequin

ggenellina mannequin commented Jan 31, 2009

I think this is a sqlite issue, not a Python one.
cursor.description should return unique column names.

@ggenellina
Copy link
Mannequin

ggenellina mannequin commented Jan 31, 2009

See http://www.sqlite.org/cvstrac/tktview?tn=3221

Try upgrading to the latest sqlite release. Or set "pragma
full_column_names=ON;"

import sqlite3
conn = sqlite3.connect(':memory:')
cursor = conn.cursor()
cursor.execute("create table T (a, b, c)")
cursor.execute("insert into T values (1, 2, 3)")
cursor.execute("insert into T values (2, 3, 4)")
conn.commit()
cursor.execute("pragma short_column_names=OFF;")
cursor.execute("pragma full_column_names=ON;")
cursor.execute("select * from T T1, T T2 where T1.a=T2.b")
print [d[0] for d in cursor.description]
# output: ['T1.a', 'T1.b', 'T1.c', 'T2.a', 'T2.b', 'T2.c']

@sockonafish
Copy link
Mannequin Author

sockonafish mannequin commented Jan 31, 2009

Ah, that's it. Thanks for the tip, this issue can be closed now.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant