Concatenation: || and CONCAT
Concatenate strings with the || operator and CONCAT(), and understand how each handles NULL inputs.
Standard Concatenation: ||
The SQL-standard operator for joining strings is ||:
SELECT first_name || ' ' || last_name AS full_name FROM users;
SELECT 'Hello, ' || name || '!' FROM users;|| with NULL = NULL
If any operand is NULL, the whole expression becomes NULL. Be explicit:
SELECT first_name || ' ' || NULL; -- NULL
-- Defend with COALESCE:
SELECT first_name || ' ' || COALESCE(last_name, '') FROM users;All lessons in this course
- Concatenation: || and CONCAT
- UPPER, LOWER, SUBSTRING, REPLACE
- TRIM, LPAD, RPAD
- Full-Text Search Introduction (tsvector, to_tsquery)