•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 402,053 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,420 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 443 | Replies: 5 | Solved
![]() |
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 100
Reputation:
Rep Power: 3
Solved Threads: 8
Hi there, I'm trying to connect to a PostGIS database (which is basically an enriched PostgreSQL database) and I'm having trouble with the INSERT statement. Here's my code:
It does sucessfully connect to the database (as per the program output) but when I query the database using the pgAdmin III SQL Query feature, I get no returned rows. I use the following SQL code to query:
I even refresh the database but still nothing is returned. There is not traceback error given by Python either.
The following SQL statement working in the Query Editor from pgAdmin:
So since my SQL seems to be working, I don't see why my code isn't working. Can someone please give me a few suggestions?
python Syntax (Toggle Plain Text)
import psycopg2 try: conn = psycopg2.connect("dbname='postgis' user='fdi' host='localhost' password='fdi'"); print "Database connection established" except: print "Critical Error: Unable to connect to the database" cur = conn.cursor() cur.execute("""INSERT INTO fdi.fdiresults (grid, index) VALUES (POINT(1, 1), 1)""")
sql Syntax (Toggle Plain Text)
SELECT * FROM fdi.fdiresults;
The following SQL statement working in the Query Editor from pgAdmin:
sql Syntax (Toggle Plain Text)
INSERT INTO fdi.fdiresults (grid, INDEX) VALUES (POINT(1, 1), 1);
•
•
Join Date: Dec 2006
Posts: 408
Reputation:
Rep Power: 2
Solved Threads: 56
•
•
•
•
I get no returned rows. I use the following SQL code to query:
SELECT * FROM fdi.fdiresults;
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 100
Reputation:
Rep Power: 3
Solved Threads: 8
Hi guys, thank you so much. Jlm699 was correct, I needed to commit the changes to the database. I knew that there was a commit call that has to be used but I was calling it on the cursor (cur)
And I agree, I haven't really seen tables being used the way I have (that is: fdi.fdiresults) but it does work. The fdi is the schema and fdiresults is the table. Clever use of SQL there mate
Once again, thanks guys!
And I agree, I haven't really seen tables being used the way I have (that is: fdi.fdiresults) but it does work. The fdi is the schema and fdiresults is the table. Clever use of SQL there mate
Once again, thanks guys!
•
•
•
•
Hi guys, thank you so much. Jlm699 was correct, I needed to commit the changes to the database. I knew that there was a commit call that has to be used but I was calling it on the cursor (cur)![]()
And I agree, I haven't really seen tables being used the way I have (that is: fdi.fdiresults) but it does work. The fdi is the schema and fdiresults is the table. Clever use of SQL there mate![]()
Once again, thanks guys!
It's understandable that you'd try to commit the cursor instead of 'conn', mainly because you've tricked yourself by using that nomenclature! The return of psycopg2.connect() is actually a database object! Maybe it'd help your thinking if you changed all instances of conn to db or my_db? That's what I did!
I'm glad we could help.
Let's Go Pens!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
age amd avatar backup blue gene breach business chips connectivity daniweb data data protection database development dos economy energy enterprise europe government hacker hardware hp ibm internet isp it linux medicine memory microsoft news open source openoffice pc ps3 recession red hat security server sql sun supercomputer supercomputing survey technology trends ubuntu working x86
- Previous Thread: Flaxible Wrapping Lines
- Next Thread: Simple graphics in python GUI - Tkinter


Linear Mode