chtd / psycopg2cffi

Port to cffi with some speed improvements
Other
177 stars 43 forks source link

cannot use string() on <cdata 'char *' NULL> error when connecting to amazon redshift #9

Closed mwhooker closed 11 years ago

mwhooker commented 11 years ago

I installed psycopg2cffi from git.

When I tried to connect to my redshift database, I got this error.

(venv)[mwhooker@Wolfe:dev/psycopg2cffi]$ python                                                                                                                                          [master] 17:37:04
Python 2.7.3 (7e4f0faa3d51, Nov 21 2012, 15:59:46)
[PyPy 2.0.0-beta1 with GCC 4.2.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``PyPy 1.6 released!''
>>>> from psycopg2cffi import compat
>>>> compat.register()
>>>> import psycopg2
>>>> conn = psycopg2.connect("dbname=*** host=*** port=5439 user=*** password=***")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "psycopg2cffi/__init__.py", line 107, in connect
    connection_factory=connection_factory, async=async)
  File "psycopg2cffi/_impl/connection.py", line 793, in _connect
    return connection_factory(dsn)
  File "psycopg2cffi/_impl/connection.py", line 118, in __init__
    self._connect_sync()
  File "psycopg2cffi/_impl/connection.py", line 134, in _connect_sync
    self._setup()
  File "psycopg2cffi/_impl/connection.py", line 590, in _setup
    libpq.PQparameterStatus(self._pgconn, 'DateStyle'))
  File "/Users/mwhooker/dev/natty/kafka2redshift/venv/site-packages/cffi/api.py", line 220, in string
    return self._backend.string(cdata, maxlen)
RuntimeError: cannot use string() on <cdata 'char *' NULL>

I am able to connect using psycopg2 just fine.

Please let me know if I can provide more information.

lopuhin commented 11 years ago

The issue is fixed, I think, but I did not manage to write a test - maybe you can suggest how can I set NULL datestyle in postgres?

mwhooker commented 11 years ago

@lopuhin I can verify that this has been resolved. Unfortunately, I'm not sure what you mean by a NULL datastyle.

thanks very much for your quick response!

lopuhin commented 11 years ago

Thank you! The error was that libpq returned NULL when queried about current date style - this is the setting described here http://www.postgresql.org/docs/9.1/static/runtime-config-client.html - but I think that generally date style is not null. Are you fine with using github version for now? I can make a minor release if it is more convenient for you.

mwhooker commented 11 years ago

Thanks for clearing that up. For what it's worth, this is the result of show datestyle in redshift

show datestyle;
 datestyle
-----------
 ISO, MDY
(1 row)

weird that it's reported as NULL.

I'm fine using the github version. It'll be a couple more weeks before I need to use this in production.

Thanks again.