Vineet Menon
Vineet Menon

Reputation: 738

python pg module error messages

pg module in python for interacting with postgres is not giving any error message for DML queries.

Is there any alternative to pg module which gives meaningful error messages.

>>>import pg 
>>>
>>>
>>>conn = pg.connect(dbname="db", user="postgres", host="localhost")
>>>print conn.query("delete from item where item_id=0")
>>>None
>>>print conn.query("delete from item where item_id=0")
>>>None                     #This should have been an error message

Upvotes: 0

Views: 1242

Answers (2)

Chris Travers
Chris Travers

Reputation: 26464

Why are you expecting an error message? I delete does not raise an error in the server if no records were found. So why do you expect a generally applicable database driver to raise an error?

I can't think of any database driver that would issue an error in that case because there may be perfectly legitimate reasons for it. In database terms, for example, an error usually means you are going to roll back a transaction.

If you are going to wrap in your own API, my recommendation is that you either decide how you want your application to address this or at most you raise warnings instead.

Upvotes: 2

Thales MG
Thales MG

Reputation: 771

Do you know the psycopg2 module? It seems a very nice module to interact with PostgreSQL via Python. There is a tutorial available, besides the modules' documentation. In the examples given in the docs, commands that fail indeed print out error messages.

I personally don't have experience in this module. But it looks very nice!

Upvotes: 0

Related Questions