postgresql psycopg2 select single value

Solutions on MaxInterview for postgresql psycopg2 select single value by the best coders in the world

showing results for - "postgresql psycopg2 select single value"
Moritz
16 Oct 2018
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import psycopg2
5import sys
6
7con = None
8
9try:
10
11    con = psycopg2.connect(database='testdb', user='postgres',
12        password='s$cret')
13
14    cur = con.cursor()
15    cur.execute('SELECT version()')
16
17    version = cur.fetchone()[0]
18    print(version)
19
20except psycopg2.DatabaseError as e:
21
22    print(f'Error {e}')
23    sys.exit(1)
24
25finally:
26
27    if con:
28        con.close()
29