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

python connection: SQL column renaming doesn't work #246

Open
leahwangibm opened this issue Jun 1, 2024 · 1 comment
Open

python connection: SQL column renaming doesn't work #246

leahwangibm opened this issue Jun 1, 2024 · 1 comment

Comments

@leahwangibm
Copy link

Hi,

I noticed that the SQL renaming clause AS doesn't work if there are no operations on those columns, AS renaming wouldn't work.
e.g.

SELECT TRIM(COL_A) AS NEW_COL_A, 
               COL_B AS NEW_COL_B

we will end up with a dataframe has header as NEW_COL_A and COL_B. Has anyone else encountered the same issue before?

query="""<SQL query>"""
df = pd.read_sql(query, db_conn) # db_conn is the database instance I set up via jaydebeapi

Thanks in advance!

@gordthompson
Copy link

I was able to reproduce the issue. This patch appears to fix it.

Index: jaydebeapi/__init__.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/jaydebeapi/__init__.py b/jaydebeapi/__init__.py
--- a/jaydebeapi/__init__.py	(revision 53b2d6a571aac5ea192b0b9d03f38ecc3f94e71d)
+++ b/jaydebeapi/__init__.py	(date 1732632090413)
@@ -488,7 +488,7 @@
                     dbapi_type = None
                 else:
                     dbapi_type = DBAPITypeObject._map_jdbc_type_to_dbapi(jdbc_type)
-                col_desc = ( m.getColumnName(col),
+                col_desc = ( m.getColumnLabel(col),
                              dbapi_type,
                              size,
                              size,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants