Articles in this section
Category / Section

How to create comma separated values in Bold BI PostgreSQL?

Published:

In some cases, you may want to create a comma-separated list of values in Bold BI. We can accomplish this using the `string_agg` function in the code view mode.


Using the string_agg Function


The `string_agg` function can be used to concatenate the values of a column with a specified delimiter. In this example, we will use the function to create a comma-separated list of values grouped by country.


Here's a sample query to achieve this:


```sql

SELECT

  "idtest"."country" AS "country",

  SUM("idtest"."value") AS "value",

  string_agg("idtest"."id"::text, ', ') AS "id",

  SUM("idtest"."rating") AS "rating"

FROM "public"."idtest" AS "idtest"

GROUP BY "country"

```


In this query, the `string_agg` function is used to concatenate the "id" column values with a comma separator. The result will be a comma-separated list of IDs for each country.


Conclusion


By using the `string_agg` function in Bold BI's code view mode, you can create a comma-separated list of IDs or other values based on your requirements. This can be helpful when you need to display aggregated data with a list of associated values.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
PK
Written by Poovarasan Kandasamy
Updated:
Comments (0)
Please  to leave a comment
Access denied
Access denied