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

Discuss the SQL Logger plugin.
DrLaban
Posts: 53
Joined: Tue Apr 28, 2015 10:30 am
Location: Norway

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

Post by DrLaban »

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)
User avatar
DaveL17
Posts: 6881
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

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

Post by DaveL17 »

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]
DrLaban
Posts: 53
Joined: Tue Apr 28, 2015 10:30 am
Location: Norway

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

Post by DrLaban »

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
DrLaban
Posts: 53
Joined: Tue Apr 28, 2015 10:30 am
Location: Norway

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

Post by DrLaban »

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
User avatar
DaveL17
Posts: 6881
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

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

Post by DaveL17 »

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]
autolog
Posts: 4000
Joined: Tue Sep 10, 2013 3:07 am
Location: West Sussex, UK [GMT aka UTC]
Contact:

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

Post by autolog »

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
Post Reply

Return to “SQL Logger”