Answers for "postgresql psycopg2 select single value"

SQL
0

postgresql psycopg2 select single value

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psycopg2
import sys

con = None

try:

    con = psycopg2.connect(database='testdb', user='postgres',
        password='s$cret')

    cur = con.cursor()
    cur.execute('SELECT version()')

    version = cur.fetchone()[0]
    print(version)

except psycopg2.DatabaseError as e:

    print(f'Error {e}')
    sys.exit(1)

finally:

    if con:
        con.close()
Posted by: Guest on October-28-2020

Code answers related to "postgresql psycopg2 select single value"

Code answers related to "SQL"

Browse Popular Code Answers by Language