Here is my code
conn_string = "dbname=detector user=postgres password=1234 host=localhost port=5432"
print "Connecting to database\n ->%s" % (conn_string)
# get a connection, if a connect cannot be made an exception will be raised here
conn = psycopg2.connect(conn_string)
which it is outputting this, which seems to be ok.
Connecting to database
->dbname=detector user=postgres password=1234 host=localhost port=5432
I use this connection as function(data, conn).
Now, I noticed strange outputs with the test command:
_measurement_id = cursor.execute(
'SELECT measurement_id FROM measurements ORDER BY time desc limit 1;'
);
which returns None through Python but inside psql, I get an integer.
I think the mistake is in not using try-catch-except in creating the connection.
And if that is the problem, how can I pass a PostgreSQL connection to functions in Python?