I want to query a table in my postgis table named Seg_060_2009 using psycopg2 and cant seem to get my query to execute. The query will execute if I name the talbe layer. Are there restrictions on table names? How can i pass a vaiable to a sql statment in python?
This works
import psycopg2try: conn = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='daniel'")except: print "I am unable to connect to the database"print ("I connected to the database")cur = conn.cursor()cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")print cur.fetchall()#cur.execute("""SELECT * FROM layer Order By sed_class """)but this wont:
import psycopg2try: conn = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='daniel'")except: print "I am unable to connect to the database"print ("I connected to the database")cur = conn.cursor()cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")print cur.fetchall()#cur.execute("""SELECT * FROM Seg_060_2009 Order By sed_class """)
أكثر...
This works
import psycopg2try: conn = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='daniel'")except: print "I am unable to connect to the database"print ("I connected to the database")cur = conn.cursor()cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")print cur.fetchall()#cur.execute("""SELECT * FROM layer Order By sed_class """)but this wont:
import psycopg2try: conn = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='daniel'")except: print "I am unable to connect to the database"print ("I connected to the database")cur = conn.cursor()cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")print cur.fetchall()#cur.execute("""SELECT * FROM Seg_060_2009 Order By sed_class """)
أكثر...