PostgreSQL Query Builder
Design tables and build PostgreSQL queries visually
Draw tables and relationships, build SELECT queries with joins, filters and grouping without writing SQL, and generate PostgreSQL CREATE TABLE statements.
- PostgreSQL
- SQL
- Query builder
- Schema
- ERD
How to use PostgreSQL Query Builder
- Pick a sample from Load a sample schema… (e-commerce, blog, clinic or project management), or open Schema Designer and use + Add table. Each new table starts with a
BIGINTidentity primary key. - Click a table’s header on the canvas to edit it: rename it, add columns, choose PostgreSQL types, tick Primary key, Not null, Unique or Identity, and set defaults, CHECKs and indexes. Drag tables by their header; Fit, + and − (or Ctrl/⌘ + scroll) control the view.
- Link tables in Add a relationship, or click the dot next to a foreign key column and then the dot next to the column it references. Choose one-to-many or one-to-one and the ON DELETE action, then confirm with Add relationship. Create junction table sets up many-to-many.
- In Visual Query Builder, choose the first table, join more tables (accepting a suggested ON condition or choosing your own), then add columns, aggregates, WHERE conditions and groups, GROUP BY, HAVING, ORDER BY, LIMIT and OFFSET. The SQL updates as you go.
- Copy the SQL, use Download query.sql / Download schema.sql, or Edit SQL by hand. Export JSON saves the whole project to a file you can Import JSON later.
How it works
Tables, columns, relationships and query parts are stored as structured data, each with a stable id, so renaming a table or column updates every join, filter and foreign key that uses it. Plain TypeScript code in your browser generates SQL from that data on every change. The same project always gives exactly the same SQL.
Schema SQL has one CREATE TABLE per table, with referenced tables first. Columns get their type (VARCHAR(n), NUMERIC(p, s) and so on), GENERATED ALWAYS AS IDENTITY, DEFAULT, PRIMARY KEY or UNIQUE, NOT NULL and CHECK. Composite primary keys, table CHECKs and foreign keys (CONSTRAINT … FOREIGN KEY … REFERENCES … ON DELETE …) are written as table constraints.
When tables reference each other in a loop, those foreign keys are added afterwards with ALTER TABLE … ADD CONSTRAINT. PostgreSQL doesn’t index foreign key columns by itself, so a CREATE INDEX is added for each one, unless you turn that off or the column is already indexed.
Query SQL is a SELECT with optional DISTINCT, INNER, LEFT, RIGHT or FULL OUTER JOIN … ON, WHERE with nested AND / OR groups, GROUP BY, HAVING, ORDER BY, LIMIT and OFFSET.
- Operators:
=,!=,>,<,>=,<=,LIKE,ILIKE,IN,NOT IN,IS NULL,IS NOT NULLandBETWEEN. - Aggregates:
COUNT,SUM,AVG,MINandMAX. - Identifiers are quoted with
"…"only when needed (capitals, spaces, reserved words such asuserororder). - Values are written as literals for the column’s type: numbers are checked, text is quoted with doubled
', and dates, timestamps, UUIDs and JSONB are typed, for exampleDATE '2026-01-31'.
Before showing any SQL, the builder checks the design the way PostgreSQL would. It catches duplicate names or names over PostgreSQL’s 63-byte limit, a foreign key that doesn’t reference a primary key or unique column, mismatched key types, SET NULL on a NOT NULL column, joins without a condition, selected columns that aren’t grouped, aggregates in WHERE, SUM on text, ORDER BY with DISTINCT on an unselected column, and invalid values.
Problems are listed in plain words, and no SQL is produced until they are fixed, so the tool never hands you a statement it knows is invalid. What this query does describes the finished query in plain sentences built from the same data, not by an AI model.
Join suggestions come only from relationships you have defined. Columns with matching names are never joined automatically.
Limits
- The tool only writes SQL text. It doesn’t connect to a database, run queries, show results, or read an existing database’s schema.
- The visual builder makes
SELECTqueries.INSERT,UPDATE,DELETE, subqueries, CTEs, window functions andUNIONare shown as examples in SQL Reference but aren’t built visually. - Supported column types:
INTEGER,BIGINT,SERIAL,BIGSERIAL,VARCHAR,TEXT,BOOLEAN,DATE,TIMESTAMP,TIMESTAMPTZ,NUMERIC,UUIDandJSONB. Defaults are a typed value or one ofCURRENT_TIMESTAMP,CURRENT_DATE,now()andgen_random_uuid(). - CHECK expressions are written into the SQL as you type them. The builder rejects
;, comments and unbalanced quotes or brackets, but doesn’t check column names or functions inside them. - Foreign keys are single-column. Join conditions compare one column with another using
=. - Schema SQL creates tables from scratch; it doesn’t produce migrations between two versions of a schema.
- Hand-edited SQL isn’t checked, read back into the visual builder, or saved with the project.
- Imported project files can be up to 2 MB, with up to 200 tables of 200 columns each. Undo keeps the last 100 changes for the current visit.
Privacy
Everything runs in your browser. Your schema and query are saved in this browser’s local storage for when you come back; nothing is uploaded, and Reset clears them. The tool never asks for database hosts, usernames or passwords. Imported JSON files are read on the page and checked field by field before use.
Frequently asked questions
Does this run my query against a database?
No. It only writes PostgreSQL SQL. Copy or download it and run it in psql, pgAdmin, DBeaver or your application.
How do I make a many-to-many relationship?
Use Create junction table under Many-to-many and pick the two tables. It adds a table such as students_courses with a foreign key to each side (both with ON DELETE CASCADE) that together form its primary key. Then join through the junction table in your query.
Why does my query show problems instead of SQL?
The builder only shows SQL it can stand behind. A common cause is grouping: once you use GROUP BY or an aggregate, every plain selected column must be in GROUP BY (grouping by a table’s primary key covers its other columns). Others are a join with no ON condition or a value that doesn’t fit the column type. The message says what to change.
Why are some names wrapped in double quotes?
PostgreSQL folds unquoted names to lower case and reserves words such as user, order and group. A name with capitals, spaces or a reserved word is quoted so it keeps working, for example "user" or "Order Total". Lower-case snake_case names never need quotes.
Is the generated SQL safe to put in my application?
Values are escaped correctly, but in application code you should pass user input as query parameters ($1, $2) instead of writing values into the SQL string. Use the generated SQL as a template and replace the literal values with parameters.
Will joins be guessed from column names?
No. A join is only suggested from a relationship you defined, and you choose whether to use it. Otherwise you pick the ON columns yourself.
More tools
- Clean Image: Inspect and remove hidden image metadata
- JWT Decoder: Decode and verify JSON Web Tokens
- Diff Checker: Compare two texts line by line
- JS Runner: Run JavaScript and TypeScript in your browser
- JSON Formatter: Format, validate and minify JSON
- Encode / Decode: Base64, URL, HTML entity and hex
- Hash Generator: MD5, SHA and HMAC of any text
- UUID Generator: Generate UUID v4 and v7 in bulk
- Timestamp Converter: Unix time ↔ human dates
- Regex Tester: Test regular expressions live
- URL Parser: Break a URL into its parts
- HTTP Status Codes: Look up any HTTP status code
- MIME Type Lookup: File extension ↔ MIME type
- Password Generator: Strong random passwords and passphrases
- Random String Generator: Random tokens, IDs and keys
- Slug Generator: Turn titles into URL slugs
- Case Converter: camelCase, snake_case, Title Case and more
- Word Counter: Count words, characters and reading time
- JSON to TypeScript: Generate TypeScript types from JSON
- JSON Diff: Compare two JSON documents structurally
- JSON to SQL: Turn JSON arrays into SQL inserts
- YAML ↔ JSON: Convert between YAML and JSON
- XML ↔ JSON: Convert between XML and JSON
- CSV ↔ JSON: Convert between CSV and JSON
- CSV Viewer: View, sort and filter CSV files
- SQL Formatter: Format and beautify SQL queries
- cURL ↔ Fetch: Convert cURL commands to fetch and back
- Markdown Editor: Write Markdown with a live preview
- Text Cleaner: Remove duplicate lines, empty lines and extra spaces
- Find & Replace: Find and replace in any text
- Cron Expression Builder: Build and explain cron schedules
- User-Agent Parser: Identify browser, OS and device from a user agent
- HTTP Headers Inspector: Paste response headers and get them explained
- JWT Generator: Create and sign test JSON Web Tokens
- Certificate Inspector: Decode PEM certificates and keys
- Meta Tag Inspector: Check a page's SEO and social tags
- UTM Builder: Build campaign URLs with UTM parameters
- URL Cleaner: Strip tracking parameters from links
- Robots.txt Generator: Create and test a robots.txt file
- Sitemap Generator: Create an XML sitemap from a list of URLs
- Image Compressor: Shrink JPEG, WebP and AVIF images in your browser
- Image Resizer: Resize images by pixels, percentage or to fit a box
- Image Converter: Convert between PNG, JPEG, WebP and AVIF
- Image to Base64: Encode images as Base64 data URIs and decode them back
- SVG Optimizer: Minify and sanitize SVG files
- Favicon Generator: Make favicon.ico, Apple and Android icons from an image or emoji
- Color Converter: HEX, RGB, HSL, OKLCH and contrast checks
- Number Base Converter: Binary, octal, decimal, hex and float bits
- IP / CIDR Calculator: Subnets, masks and IP ranges for IPv4 and IPv6
- JSONPath Query: Query JSON with JSONPath expressions
- JSON Schema Validator: Validate JSON against a schema, or generate one
- Semver Checker: Check versions against semver ranges
- chmod Calculator: Unix permissions: rwx ↔ octal
- .env Diff: Compare and validate .env files
- TOTP Generator: Generate and verify 2FA codes
- String Escaper: Escape and unescape strings for any language
- Unicode Inspector: See every character, code point and hidden symbol
- Mock Data Generator: Generate realistic fake data
- QR Code Generator: Create QR codes for links, Wi-Fi and contacts
- Lorem Ipsum Generator: Placeholder text in paragraphs, sentences or words
- Date Calculator: Date differences, business days and durations
- Unit Converter: Convert bytes, lengths, weights, temperatures and more
- Query CSV with SQL: Run SQL queries on CSV files
- PDF Merge & Split: Merge, split, reorder and rotate PDFs
- PDF Metadata Cleaner: See and remove hidden PDF metadata
- Office Metadata Cleaner: Remove author and revision data from Word, Excel and PowerPoint
- Images to PDF: Combine images into one PDF
- Image Editor: Crop, rotate, resize and adjust images
- Encrypt / Decrypt Text: Encrypt text with a passphrase (AES-GCM)
- SSH Key Generator: Generate Ed25519 and RSA SSH keys locally
- Email Header Analyzer: Trace an email's path and check SPF, DKIM and DMARC
- JSON to Code: Generate Go, Python, Rust, Java, C# and Kotlin models from JSON
- docker run ↔ Compose: Convert docker run commands to docker-compose and back
- Color Palette Extractor: Pull the dominant colours out of any image
- Password Strength Checker: How long would your password take to crack?
- SPF / DKIM / DMARC Checker: Validate and explain email DNS records
- Kubernetes YAML Checker: Validate and explain Kubernetes manifests
- .gitignore Generator: Build a .gitignore from presets
- CSP Builder: Build and check a Content-Security-Policy
- JSON-LD Generator: Create schema.org structured data
- Open Graph Image Generator: Make 1200×630 social preview images
- CSS Generator: Gradients, shadows, clamp() and more
- Time Zone Meeting Planner: Find meeting times across time zones
- HAR Viewer: Inspect browser network recordings (HAR)
- Log Viewer: Filter and search JSON log files
- TOML ↔ JSON: Convert between TOML and JSON
- HTML to Markdown: Turn HTML into clean Markdown
- Markdown Table Generator: Build and format Markdown tables
- GraphQL Formatter: Format and minify GraphQL
- Protobuf Decoder: Decode raw protobuf bytes
- Bcrypt Generator: Hash and verify bcrypt passwords
- Image Diff: Compare two images and see what changed
- Keyboard Event Viewer: See key, code, keyCode and modifiers for every keypress
- JSON Tree Viewer: Explore large JSON as a collapsible tree
- XML Formatter: Format, minify, validate and query XML
- HTML & CSS Minifier: Minify or beautify HTML and CSS safely
- Aspect Ratio Calculator: Work out sizes that keep the same ratio
- Morse Code Translator: Text ↔ Morse code, with sound
- Text to Speech: Read text aloud with your browser's voices
- Placeholder Image Generator: Make placeholder images of any size
- nginx Config Generator: Build nginx server blocks
- Duplicate File Finder: Find duplicate files by content
- Invoice Generator: Create PDF invoices in your browser
- QR Code Reader: Read QR codes from images
- Barcode Generator: Create Code 128, EAN-13, UPC-A and more
- Signature Pad: Draw a signature as a transparent PNG
- Loan / EMI Calculator: Monthly payments, interest and schedule
- Percentage Calculator: Percent of, change, discounts and tax
- Stopwatch & Timer: Stopwatch, countdown and Pomodoro
- Notepad: Quick notes saved in your browser
- Random Picker: Pick names, make teams, flip coins
- PDF to Images: Convert PDF pages to JPG or PNG
- Excel to CSV / JSON: Convert .xlsx sheets to CSV or JSON
- SIP & Compound Interest Calculator: See how investments grow over time
- Age Calculator: Exact age in years, months and days