Database Connection
Connect to the Midpage read replica using PostgreSQL.
Connection String
postgresql://user:password@host:port/database
Contact us to obtain your connection credentials.
Connecting with psql
psql "postgresql://user:password@host:port/database"
Connecting with Python
import psycopg2
conn = psycopg2.connect(
host="host",
port="port",
database="database",
user="user",
password="password"
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM opinions.courts LIMIT 10")
rows = cursor.fetchall()
Connecting with Node.js
import { Pool } from 'pg'
const pool = new Pool({
connectionString: process.env.DATABASE_URL
})
const result = await pool.query('SELECT * FROM opinions.courts LIMIT 10')
console.log(result.rows)
Schema Access
All tables are in the opinions schema:
-- List all tables
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'opinions';
-- Describe a table
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'opinions'
AND table_name = 'courts';