Array_agg in postgres selectively quotes

前端 未结 2 761
走了就别回头了
走了就别回头了 2021-01-26 22:15

I have a complex database with keys and values stored in different tables. It is useful for me to aggregate them when pulling out the values for the application:



        
2条回答
  •  长情又很酷
    2021-01-26 23:12

    Unfortunately, this is the inconsistent standard that PostgreSQL uses for formatting arrays. See "Array Input and Output Syntax" for more information.

    Clodoaldo's answer is probably what you want, but as an alternative, you could also build your own result:

    SELECT '{'||array_to_string(array_agg(txt::text), ',')||'}' FROM test;
    

提交回复
热议问题