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
SQL LIKE Wildcards: %, _, and ESCAPE Explained
By Sharon Ben-Moshe · Aug 21, 2026
Use SQL LIKE for text patterns without accidental matches. Learn %, _, literal wildcard escaping, case sensitivity, and portable examples.
Read postSQL CAST vs CONVERT: Safe Type Changes Across Databases
By Sharon Ben-Moshe · Aug 21, 2026
CAST turns one SQL data type into another. Learn when CONVERT differs, how invalid values fail, and how to write portable conversions.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.