
It's about concatenation with an actual NULL value, with the concatenation operator || and still getting a non-null result. The syntax for the operator in PostgreSQL is: string1 string2 stringn Parameters or Arguments string1 The first string to concatenate. Note: CASE or COALESCE catching NULL values are typically good style, but that's not what this question is about. Character string operators are valid upon values of types char, varchar, and PostgreSQL's own text type. It's a bit of a trick question as I know the answer. PostgreSQL contains a comprehensive set of character string operators, from simple text concatenation and string comparison, to a strong set of regular expression matching. Test-#, (text 'foo' || col) IS NULL AS result_is_nullĪ client of mine stumbled over this, relying on the result to be NULL, and I found it intriguing enough to share. Note that you also need to consciously add. You can see from above that PostgreSQL took care of transforming the number to a string to attach it to the rest. The first uses the operator: select Join these strings with a number 23 result. In other words, how is this possible? test=# SELECT col IS NULL AS col_is_null PostgreSQL offers two ways to concatenate strings. Is it possible to concatenate a text and a NULL value and get a non-null result? Test-#, (NULL::bigint || text 'baz') IS NULL Test-#, (text 'bar' || char '1' || NULL ) IS NULL test=# SELECT (text 'foo' || NULL) IS NULL postgresql - Concatenate string based on a condition - Database Administrators Stack Exchange Concatenate string based on a condition Ask Question Asked 2 years, 3 months ago Modified 3 months ago Viewed 319 times 0 I want to assign a value to a new column based on a condition for other rows associated with a userid.
POSTGRESQL STRING CONCATENATION HOW TO

However, the string concatenation operator ( ||) still accepts non-string input, so long as at least one input is of a string type In Postgres, every type has a text representation and can be cast to text.

The concatenation operator || can concatenate any string type values, returning text.
