postgresqlconcatenationdynamic-sql

String concatenation using operator "||" or format() function


Should we use the concatenation operator || or the format() function in trigger functions?

Is there any advantage of using one over the other or does it come down to personal preference and readability?

Would you say for simple concatenation, use the operator but for more complex concatenation, use the format function?


Solution

  • There are basically 4 standard tools for concatenating strings. Simplest / cheapest first:

    || (the standard SQL concatenation operator) ...

    concat() ...

    concat_ws() ("with separator") ...

    format() ...

    Further reading: