Guides — 34 for PostgreSQL

PostgreSQL guides

Everything we've written about PostgreSQL: connections, SQL patterns, imports, clients, and comparisons.

01Connect & How-To

Connect & How-To

Connect & How-ToPostgreSQL

How to Connect to PostgreSQL from Ruby

Connect to PostgreSQL from Ruby with the pg gem, Sequel, or ActiveRecord. Working code for connections, connection pools, parameterized queries, prepared statements, and the sslmode and PostgreSQL 18 cancel-key traps.

7 min read
Connect & How-ToPostgreSQL

How to Connect to PostgreSQL from PHP

Connect to PostgreSQL from PHP with PDO and the pgsql extension: prepared statements, the PDO driver subclasses added in 8.4, persistent connections, transactions, SSL, and the errors you actually hit.

6 min read
Connect & How-ToPostgreSQL

How to Connect to PostgreSQL from C# (.NET)

Connect to PostgreSQL from C# with Npgsql: ADO.NET basics, async commands, parameters, connection pooling, NpgsqlDataSource, Dapper and EF Core, SSL, and the errors you actually hit.

8 min read
Connect & How-ToPostgreSQL

How to Connect to PostgreSQL from Java

Connect to PostgreSQL from Java with the pgJDBC driver: DriverManager, DataSource, PreparedStatement, HikariCP pooling, SSL, and the errors you actually hit in production.

8 min read
Connect & How-ToPostgreSQL

How to Connect to PostgreSQL from Go

Connect to PostgreSQL from Go with pgx or lib/pq. Working code for connection pools, the database/sql vs native pgx interface decision, context timeouts, parameterized queries, and the TLS sslmode trap.

7 min read
Connect & How-ToPostgreSQL

How to Connect to PostgreSQL from Node.js

Connect to PostgreSQL from Node.js with node-postgres (pg) or Postgres.js. Working code for pools and queries, the SSL self-signed certificate trap, parameterized queries, and which client to pick.

6 min read
Connect & How-ToPostgreSQL

How to Connect to PostgreSQL from Python

Connect to PostgreSQL from Python with psycopg 3, psycopg2, asyncpg, or SQLAlchemy. Working code for connections, queries, pooling, and the gotchas that bite in production.

8 min read
Connect & How-ToPostgreSQL

Understanding Window Functions in PostgreSQL

Master PostgreSQL window functions like ROW_NUMBER(), RANK(), and LAG() to perform advanced analytics and row-level calculations.

3 min read
02SQL How-To

SQL How-To

SQL How-ToPostgreSQL

PostgreSQL Arrays: Operators, Functions, and Practical Patterns

Learn how to work with PostgreSQL array types -- creation, operators, functions like unnest and array_agg, indexing with GIN, and common patterns for storing and querying arrays.

5 min read
SQL How-ToPostgreSQL

PostgreSQL EXPLAIN ANALYZE: Reading Query Plans

Learn how to use EXPLAIN and EXPLAIN ANALYZE in PostgreSQL to understand query execution, identify bottlenecks, and optimize slow queries -- including how to read nodes, costs, and buffer statistics.

5 min read
SQL How-ToPostgreSQL

PostgreSQL Generated Columns: STORED and VIRTUAL

Learn how to use generated columns in PostgreSQL -- automatically computed values derived from other columns -- including STORED vs VIRTUAL modes (PostgreSQL 18+), use cases, and limitations.

4 min read
SQL How-ToPostgreSQL

PostgreSQL LATERAL Joins: When and How to Use Them

Understand PostgreSQL LATERAL joins -- what they are, how they differ from regular subqueries, and practical patterns like top-N per group, calling functions row-by-row, and flattening arrays.

5 min read
SQL How-ToPostgreSQL

PostgreSQL Table Partitioning: Range, List, and Hash

Learn how to use declarative table partitioning in PostgreSQL -- range, list, and hash strategies -- with examples, partition pruning, indexing, and maintenance patterns for large tables.

6 min read
SQL How-ToPostgreSQL

PostgreSQL Recursive Queries: WITH RECURSIVE for Hierarchical Data

Learn how to use PostgreSQL's WITH RECURSIVE to query hierarchical and graph-structured data -- org charts, categories, file trees, and bill-of-materials -- with practical examples and performance tips.

6 min read
SQL How-ToPostgreSQL

PostgreSQL Subqueries: A Practical Guide

Learn how to use subqueries in PostgreSQL -- scalar, row, table, correlated, EXISTS, and ANY/ALL -- with real examples and performance guidance.

4 min read
SQL How-ToPostgreSQL

PostgreSQL Transactions: ACID, COMMIT, ROLLBACK, and Savepoints

Understand how transactions work in PostgreSQL -- BEGIN, COMMIT, ROLLBACK, isolation levels, and savepoints -- with practical examples for reliable data operations.

5 min read
SQL How-ToPostgreSQL

PostgreSQL UPSERT: INSERT ON CONFLICT Explained

Learn how to use PostgreSQL's INSERT ON CONFLICT to upsert data -- insert new rows or update existing ones atomically, with examples covering DO NOTHING, DO UPDATE, and partial indexes.

4 min read
SQL How-ToPostgreSQL

PostgreSQL Views and Materialized Views: A Complete Guide

Learn how to create and use regular views and materialized views in PostgreSQL, when to use each, and how to manage refresh strategies.

4 min read
SQL How-ToPostgreSQL

PostgreSQL Aggregate Functions: COUNT, SUM, AVG, ARRAY_AGG, and More

How to use PostgreSQL aggregate functions with GROUP BY, HAVING, FILTER, DISTINCT, and ordered aggregates. Covers standard and advanced aggregates.

6 min read
SQL How-ToPostgreSQL

PostgreSQL CTE: A Guide to Common Table Expressions

Learn how to use Common Table Expressions (CTEs) in PostgreSQL to write cleaner, more maintainable, and complex queries.

4 min read
SQL How-ToPostgreSQL

PostgreSQL Date and Time Functions: A Practical Guide

How to work with dates and timestamps in PostgreSQL: date_trunc, extract, age, intervals, timezone handling, and common patterns for time-series analysis.

5 min read
SQL How-ToPostgreSQL

Full-Text Search in PostgreSQL: tsvector, tsquery, and GIN Indexes

How to implement full-text search in PostgreSQL using tsvector and tsquery, ranking results, handling multiple languages, and indexing for performance.

5 min read
SQL How-ToPostgreSQL

PostgreSQL Indexes Explained: B-tree, GIN, GiST, BRIN, and More

Understand every PostgreSQL index type, when to use each, how they affect query performance, and common pitfalls to avoid.

6 min read
SQL How-ToPostgreSQL

PostgreSQL Joins: A Complete Guide with Examples

Learn every type of join in PostgreSQL -- INNER, LEFT, RIGHT, FULL, CROSS, SELF, and LATERAL -- with real examples and common pitfalls.

6 min read
SQL How-ToPostgreSQL

JSON and JSONB Queries in PostgreSQL

A practical guide to querying JSON and JSONB data in PostgreSQL, covering operators, path expressions, indexing, and common patterns.

5 min read
SQL How-ToPostgreSQL

Pivot Tables in PostgreSQL: crosstab, CASE, and FILTER

How to create pivot tables in PostgreSQL using the crosstab() function from tablefunc, CASE expressions, and the FILTER clause. With working examples.

5 min read
SQL How-ToPostgreSQL

PostgreSQL String Functions: A Practical Reference

How to manipulate text in PostgreSQL: substring, concat, trim, regexp_replace, split_part, format, and more -- with real-world examples.

5 min read
← All guides