Why Your AI's Full Name Comes Back Blank
Asked for first name + last name and got NULL whenever one side was missing. In Postgres and SQL Server, string concatenation with NULL makes the whole result NULL. MySQL CONCAT skips NULLs instead — same request, different blank.
You ask for a CSV of customers: full name, email. Half the name column is blank. Those people have a first name in the table. last_name is NULL, and in Postgres that is enough to erase the whole concatenation.
NULL does not mean "skip this part"
-- Postgres: if last_name is NULL, the entire expression is NULL
SELECT first_name || ' ' || last_name AS full_name FROM customers;
-- SQL Server: same with +
SELECT first_name + ' ' + last_name FROM customers;
'Ada' || ' ' || NULL is NULL, not 'Ada '. That is the same three-valued rule as NULL + 5: unknown poisons the expression.
MySQL's CONCAT() is the exception people remember from the wrong database:
-- MySQL: NULLs are skipped, you still get 'Ada '
SELECT CONCAT(first_name, ' ', last_name) FROM customers;
So a prompt that "worked" against MySQL goes blank on Postgres or SQL Server with no syntax error — another same SQL, different database footgun.
The fix
Make each piece non-NULL before you glue:
-- works everywhere
SELECT TRIM(
COALESCE(first_name, '') || ' ' || COALESCE(last_name, '')
) AS full_name
FROM customers;
Postgres and MySQL also have CONCAT_WS (concat with separator), which skips NULL parts so you don't get a dangling space from a missing middle name:
SELECT CONCAT_WS(' ', first_name, last_name) AS full_name FROM customers;
SQL Server has CONCAT() too (2012+), which likewise treats NULL as ''. The dangerous operators are Postgres || and SQL Server +.
How to catch it
If a "name" or "label" column in the result is NULL more often than the source columns:
How many rows have first_name IS NOT NULL?
How many have full_name IS NULL in your SELECT?
If those differ, you're concatenating NULLs. Show the expression.
Same check for city || ', ' || country, invoice line descriptions, and any filter on the concatenated string.
The prompt that heads this off
When concatenating text (names, addresses, labels), don't use
Postgres || or SQL Server + on raw columns. COALESCE each part to ''
or use CONCAT / CONCAT_WS. Say which database you're on. If a display
column is NULL, check whether one of the inputs was NULL before
assuming the row is empty.
The short version
One missing last name should not delete the first name. In Postgres and SQL Server, || / + will do exactly that. COALESCE or CONCAT_WS is the version that still prints "Ada."
Read-only MCP gateway: mcpserver.design.
Related reading: