SQL String Concatenation Across Databases
By Sharon Ben-Moshe · August 21, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Concatenate SQL strings with || or CONCAT, but NULL behavior differs by database. See portable patterns for PostgreSQL, MySQL, SQL Server, and BigQuery.
Quick answer
SQL string concatenation is not fully portable. PostgreSQL and BigQuery support `||`; MySQL, SQL Server, and BigQuery support CONCAT. The important difference is NULL handling: check the documented behavior of the chosen function before building labels, keys, or search text.
FAQs
What operator concatenates strings in SQL?
The `||` operator concatenates strings in PostgreSQL and BigQuery. Other databases also offer functions such as CONCAT, so confirm the target dialect before choosing syntax.
Does CONCAT ignore NULL values?
It depends on the database. SQL Server CONCAT converts NULL values to empty strings, while MySQL CONCAT returns NULL when an argument is NULL. Check the product documentation and make the required behavior explicit.
Why use COALESCE with SQL concatenation?
COALESCE can supply an empty string for an optional value, making the intended NULL behavior visible. It also makes test cases for incomplete names, addresses, or labels easier to reason about.
Is + a safe string concatenation operator in SQL?
Not as a portable choice. SQL Server supports + for strings, but type precedence and settings can affect behavior. Prefer the database’s documented CONCAT or `||` form for the query being written.
Keep reading
The Comprehensive Guide to SQL Data Types: Storage, Precision, and Cross-Dialect Portability
By Sharon Ben-Moshe · Oct 13, 2026
The complete guide to SQL data types across PostgreSQL, MySQL, SQL Server, and SQLite. Numeric precision, character sets, timestamps, and JSON.
Read postThe Definitive Guide to SQL Window Functions: Syntax, Framing, and Real-World Recipes
By Sharon Ben-Moshe · Oct 13, 2026
The comprehensive guide to SQL window functions. Master OVER, PARTITION BY, ORDER BY, window frames (ROWS vs RANGE), and ranking recipes.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.