How do I edit this json?

61 views Asked by At

I have this code in my VIEW:

SELECT json_object_agg(code,value) FROM table1

It generates this in my postgREST api:

[{"json_object_agg":"{code1: value1, code2: value2, ...}"]

I want to remove the json_object_agg to make it like this:

[{code1: value1, code2: value2, ...}]

How do I do that?

1

There are 1 answers

0
Vao Tsun On

You can't have empty result set name. I assume this is related to your previous question where you were getting

t=# select json_object_agg(code,value) from tt;
                  json_object_agg
----------------------------------------------------
 { "ALLOW_MAC_ADDR" : "1", "USER_ALIAS" : "James" }

So if you try to name the column with empty value (closest I can think of from your post requirements), you get the error:

t=# select json_object_agg(code,value) "" from tt;
ERROR:  zero-length delimited identifier at or near """"
LINE 1: select json_object_agg(code,value) "" from tt;
                                       ^

Of course you can mokey hack it with space character, like:

t=# select json_object_agg(code,value) " " from tt;

----------------------------------------------------
 { "ALLOW_MAC_ADDR" : "1", "USER_ALIAS" : "James" }

which is ALMOST no name, but I assume you have to modify your "postgREST api" in order to do it properly - ignoring the result set attribute name