[SOLVED]: How to query a Postgres DB -> value in variable

Posted on
Sun May 10, 2015 8:20 am
DrLaban offline
Posts: 53
Joined: Apr 28, 2015
Location: Norway

Re: How to query a Postgres DB and put value in variable

Clean install and this time I don't get the "not found" error for the psycopg2 module :)

But now I get this one :(

Script Error embedded script: dlopen(/Library/Python/2.6/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Library/Python/2.6/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/psycopg2/_psycopg.so
Script Error Exception Traceback (most recent call shown last):

embedded script, line 1, at top level
File "/Library/Python/2.6/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.6/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Library/Python/2.6/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/psycopg2/_psycopg.so


This is the script I try to execute btw:

import psycopg2

try:
conn = psycopg2.connect(database="indigo_history", user="postgres", password="", host="127.0.0.1", port="5432")
cursor = conn.cursor()
cursor.execute("SELECT to_char(max(accumenergytotal) - min(accumenergytotal),'99999999D9') FROM device_history_363422168 WHERE ts > CURRENT_TIMESTAMP - INTERVAL '1440 minutes'")
rows = cursor.fetchall()
except:
indigo.server.log(u"Unable to open database.")

foo = str(rows[0][0])
indigo.variable.updateValue(898940884, foo)

Posted on
Sun May 10, 2015 9:16 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: How to query a Postgres DB and put value in variable

Please report back if you are able to figure out how to fix this.

Thanks!
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun May 10, 2015 11:15 am
DrLaban offline
Posts: 53
Joined: Apr 28, 2015
Location: Norway

Re: How to query a Postgres DB and put value in variable

When I google that message it seems like a problem with 32/64-bits. Some kinda mismatch.

What OS X version do you run, Dave? I'm running 10.9 (Mavericks)

Also - which versions of..?
PostgreSQL
Psycopg2

Posted on
Sun May 10, 2015 3:44 pm
DrLaban offline
Posts: 53
Joined: Apr 28, 2015
Location: Norway

Re: How to query a Postgres DB and put value in variable

FINALLY!!! It's working :D 6 hours of test and fail...

Second clean install of my server today after A LOT of testing and failing :p

Here's what I did.

- Clean install of OSX 10.9

- Installed PostgreSQL server from the offical dmg

- Installed xcode and command line tools

- Downloaded the source package of psycopg2 and edited the SETUP.CFG file to include the path to my pg_config for the PostgreSQL installation.
pg_config=/Library/PostgreSQL/Versions/9.0.13/bin/pg_config

- Installed psycopg2 using "sudo python2.6 setup.py install" from the extracted psycopg2 source package

Then I restored the backup of my Indigo Application support folder and installed Indigo again.

SUCCESS!

I'm a happy camper and my wife think I'm nuts.... ;) :D

Posted on
Sun May 10, 2015 5:55 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: [SOLVED]: How to query a Postgres DB -> value in variabl

Excellent news! Thanks for reporting back. You don't need this anymore, but I can report:

OS X: 10.9.5
Postgres: 9.6.3_0
psycopg2: 2.6

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed May 04, 2016 8:59 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: How to query a Postgres DB and put value in variable

Hi DrLaban,
DrLaban wrote:
FINALLY!!! It's working :D 6 hours of test and fail... ...

I have just used your solution to install psycopg2 - Thanks for your efforts and explaining how to do it. :D

Who is online

Users browsing this forum: No registered users and 2 guests