string
CONCAT
Joins two or more strings end-to-end and returns a single string. CONCAT is portable across MySQL, Postgres 9.1+, and SQLite 3.44+; the standard || operator works in Postgres and SQLite but not MySQL unless PIPES_AS_CONCAT is set.
CONCAT(str1, str2, ...) | str1 || str2 (Postgres/SQLite) Parameters / Modifiers
| Parameter | Purpose |
|---|---|
| CONCAT_WS(sep, ...) | Concatenate with a separator, skipping NULLs (MySQL, Postgres) |
| || | SQL-standard concat operator in Postgres/SQLite |
| FORMAT(fmt, ...) | Postgres printf-style formatter that also concatenates |
Examples
SELECT CONCAT(first_name, ' ', last_name) FROM users; Full name string per user
SELECT first_name || ' ' || last_name FROM users; Same result in Postgres/SQLite using ||
SELECT CONCAT_WS('-', '2026','07','16'); Returns '2026-07-16', skipping any NULL argument
SELECT CONCAT('x', NULL, 'y'); MySQL returns NULL; Postgres returns 'xy' (CONCAT ignores NULLs)
Dialect notes / Gotcha
Behaviour with NULL differs: MySQL CONCAT returns NULL if any arg is NULL, Postgres CONCAT ignores NULLs. The || operator in MySQL means logical OR by default — use CONCAT instead.
Related functions
STRING_AGG / GROUP_CONCAT
Concatenates non-NULL string values across a group into a single delimited string. Postgres and SQL Server spell it STRING_AGG; MySQL and SQLite use GROUP_CONCAT with a SEPARATOR clause.
COALESCE
Returns the first non-NULL argument, or NULL if every argument is NULL. Short-circuit evaluated — later expressions are not computed once a non-NULL value is found.
SUBSTRING
Extracts a substring by 1-based start position and optional length. All three dialects support the comma-argument form; Postgres also accepts the SQL-standard FROM/FOR clauses and POSIX regex extraction.
LENGTH / CHAR_LENGTH
Returns the number of characters in a string (CHAR_LENGTH) or the number of bytes (LENGTH in MySQL). Postgres and SQLite LENGTH return character count for text, matching CHAR_LENGTH.
REPLACE
Replaces every occurrence of from_str inside source with to_str. Case-sensitive in Postgres and SQLite; MySQL follows the column's collation.
← All SQL functions · SQL cheat sheet · Window functions · PostgreSQL cheat sheet