involves installing a driver and configuring a Data Source Name (DSN) to connect applications (e.g., Excel, Power BI, Tableau, custom apps) to a PostgreSQL database.
Use Unicode (utf-8) for better handling of international characters. odbc postgresql
import pyodbc # Connect using the DSN configured earlier conn = pyodbc.connect('DSN=PG_Sales;UID=user;PWD=password') cursor = conn.cursor() cursor.execute("SELECT * FROM my_table") for row in cursor.fetchall(): print(row) Use code with caution. 5. Troubleshooting and Best Practices involves installing a driver and configuring a Data
# /etc/odbcinst.ini (driver registration) [PostgreSQL] Description = PostgreSQL ODBC driver Driver = /usr/lib/x86_64-linux-gnu/psqlodbc.so Setup = /usr/lib/x86_64-linux-gnu/psqlodbc.so Driver64 = /usr/lib/x86_64-linux-gnu/psqlodbc.so Setup64 = /usr/lib/x86_64-linux-gnu/psqlodbc.so # ~/.odbc.ini or /etc/odbc.ini (DSN definition) [MyPostgresDB] Driver = PostgreSQL Server = localhost Port = 5432 Database = mydb Username = postgres Password = secret odbc postgresql