sfu-db / connector-x

Fastest library to load data from DB to DataFrames in Rust and Python
https://sfu-db.github.io/connector-x
MIT License
1.99k stars 161 forks source link

Syntax error on simple Redshift query with Postgres protocol #440

Open turar opened 1 year ago

turar commented 1 year ago

What language are you using?

Python 3.9

What version are you using?

0.3.1

What database are you using?

Redshift

What dataframe are you using?

Pandas

Can you describe your bug?

Running a simple query like SELECT * from TABLE results in the following Python error:

  File "...<omitted>.../venv/lib/python3.9/site-packages/connectorx/__init__.py", line 224, in read_sql
    result = _read_sql(
RuntimeError: db error: ERROR: syntax error at or near "("

Note that supplied SQL has no character "(".

What are the steps to reproduce the behavior?

Database setup if the error only happens on specific data or data type

Any Redshift table. Tested on cluster with 10 nodes of type dc2.large. Same query works with sqlalchemy-redshift / psycopg2 on same cluster.

Example query / code
import connectorx

sample_redshift_url = "postgres://username:password@host:5432/schema"
sql = "select * from any_table"
result = connectorx.read_sql(sample_redshift_url, sql)

What is the error?

  File "...<omitted>.../venv/lib/python3.9/site-packages/connectorx/__init__.py", line 224, in read_sql
    result = _read_sql(
RuntimeError: db error: ERROR: syntax error at or near "("
wangxiaoying commented 1 year ago

Hi @turar , please use redshift:// in the connection string or set protocol='cursor' to connect to redshift.

marcosdetry commented 1 year ago

Correct. I had the same error and was solved putting the redshift:// in the connection string