Column names in cursor.description contain unnecessary characters
See original GitHub issueDriver version
2.0.876
Redshift version
Redshift 1.0.23412
Client Operating System
Mac OS 10.15.7
Python version
3.9.1
Table schema
bookname varchar author varchar
Problem description
-
Expected behaviour: When the table has columns
bookname
andauthor
, column names in cursor.description are also available asbookname
andauthor
. -
Actual behaviour: What I got from cursor.description were
b'bookname'
andb'author\xe2\x80\x8e'
. -
Error message/stack trace: No error message for this issue.
-
Any other details that can be helpful: See the reproduction code.
Python Driver trace logs
No trace for this issue.
Reproduction code
Code
# This is the same as the sample code on README
cursor: redshift_connector.Cursor = conn.cursor()
cursor.execute("create Temp table book(bookname varchar,author varchar)")
cursor.executemany("insert into book (bookname, author) values (%s, %s)",
[
('One Hundred Years of Solitude', 'Gabriel García Márquez'),
('A Brief History of Time', 'Stephen Hawking')
]
)
cursor.execute("select * from book")
result: tuple = cursor.fetchall()
print(result)
# This is the piece of code that I added:
for field in cursor.description:
print(field)
Output
(['A Brief History of Time', 'Stephen Hawking'], ['One Hundred Years of Solitude', 'Gabriel García Márquez'])
(b'bookname', 1043, None, None, None, None, None)
(b'author\xe2\x80\x8e', 1043, None, None, None, None, None)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
pyodbc cursor.description is empty and query results fail to be ...
The dataframe is returned without column names; The true error underlying the empty cursor.description is raised to the user.
Read more >How do I get a list of column names from a psycopg2 cursor?
In my case the "as col_a" was unnecessary. I omitted it and the records returned by the cursor used the column names from...
Read more >Get Column names with pyodbc - Snowflake Community
When connecting to other sources, the cursor.description var from pyodbc normally has the field names, but when I connect to snowflake the names...
Read more >Fetching Python Database Cursors by Column Name
Today I got asked if you can index in to rows returned by ibm_db_dbi by column name. While this doesn't come out of...
Read more >6 Performing SQL Operations from PL/SQL - Oracle Help Center
In a cursor FOR loop, PL/SQL creates a %ROWTYPE record with fields corresponding to columns in the result set. The fields have the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @Brooke-white , Thanks for your investigation, it was nice to find out a code-specific issue and not a driver’s. And I’ve just figured out that the type of the column names was
bytes
and I needed todecode()
them before using them as strings.Problem solved. Thank you so much for your help!
Hi @meih ,
I was playing around with this issue a bit and pasted the queries in question into the Redshift query editor, which showed there is a “hidden” unicode character
\u200e
present afterauthor
. This is the cause of this issue. I’ve included a screenshot below which highlights this character.If you try executing the statements pasted below, which do not contain this character, you should see no issue:
I will update the project
README
with the corrected queries.