connector-x icon indicating copy to clipboard operation
connector-x copied to clipboard

Syntax error on simple Redshift query with Postgres protocol

Open turar opened this issue 2 years ago • 2 comments

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 "("

turar avatar Jan 28 '23 16:01 turar

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

wangxiaoying avatar Feb 10 '23 02:02 wangxiaoying

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

marcosdetry avatar Feb 17 '23 23:02 marcosdetry