I am getting error for below query. Basically to use ||
& distinct
together.
select string_agg( 'pre' || distinct user.col, 'post')
It works fine like this
select string_agg( 'pre' || user.col, 'post')
& this
select string_agg(distinct user.col, 'post')
PostgreSQL ARRAY_AGG() function is an aggregate function that accepts a set of values and returns an array where each value in the input set is assigned to an element of the array.
STRING_AGG is an aggregate function that takes all expressions from rows and concatenates them into a single string. Expression values are implicitly converted to string types and then concatenated.
select string_agg(distinct 'pre' || user.col, 'post')
As the above will deny the use of an index in the distinct
aggregation take the 'pre'
out
select 'pre' || string_agg(distinct user.col, 'postpre')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With