Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
from here zetcode.com/db/postgresqlpythontutorial
kind of like an off tutorial
#!/usr/bin/python
# -*- coding: utf-8 -*-
import psycopg2
import sys
con = None
try:
con = psycopg2.connect(database='testdb', user='janbodnar')
cur = con.cursor()
cur.execute('SELECT 1 from mytable')
ver = cur.fetchone()
print ver //здесь наш код при успехе
except psycopg2.DatabaseError, e:
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()
you can run a query and, based on its results, find out if there is a table:
SELECT *
FROM pg_tables
WHERE tablename = 'search_table_name'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question