


If any operand is null then the concatenation function moves to the next operand, leaving previous and subsequent results as they would had the null operand not been present. Just concatenate the fields like this: SELECT name ':' stringagg (book, ',') FROM authors where id 1 Edit: If your SQL returns multiple names you need to group by name (if you have multiple authors with the same name it gets a bit more complicated. PostgreSQL provides us with the following ways to concatenate strings and numbers: The CONCAT() function. The concatenation operator can concatenate any string type values, returning text. If any operand is null then the concatenation operator result is NULL.Syntax: Consider the following syntax of the CONCAT () function: CONCAT ( string1, string2. In pre-historical PostgreSQL, this notation was commonly used to. This type casts one of the columns to a Text type, making the operation valid again as one String is now present. To do this operation, we can use: select id::text age from tab. While the concatenation operator (||) and the function (concat) combine strings there is a big difference between them: how they handle nulls. The concat, concatws and format functions are variadic, so it is possible to pass the values to be concatenated or formatted as an array marked with the VARIADIC keyword (see Section 35.4.5).The arrays elements are treated as if they were separate ordinary arguments to the function. The PostgreSQL CONCAT () function ignores the NULL input if passed, which means we can concatenate the strings even if one of the input strings from a list of arguments provided is NULL. Use Typecast ( :: Notation) for Concatenation in PostgreSQL.
