Search code examples
sqlpostgresqlaggregate-functionsplpgsqlstring-concatenation

Concatenate and remove brackets


I am using Postgres and this is the return of a plpgsql function.

point = x||','||y;

The following is the output I get from the function:

"(14.5084692510445),(35.8988013191481)"

The thing is that I would like to output the values surrounded without any brackets. Is it possible to be done?


Solution

  • It depends on the data types involved, which are missing in your question.

    For string types use trim():

    SELECT trim (x, '()') || ',' || trim (y, '()')
    

    To provide for potential NULL values, you may want to use concat_ws() in addition:

    SELECT concat_ws(',', trim (x, '()'), trim (y, '()'))
    

    concat_ws() was introduced with Postgres 9.1.