Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse json_agg as json #78

Open
benbro opened this issue May 13, 2024 · 1 comment
Open

parse json_agg as json #78

benbro opened this issue May 13, 2024 · 1 comment

Comments

@benbro
Copy link
Contributor

benbro commented May 13, 2024

Is it possible to parse the json and jsob types?
Currenty pgo returns the column as binary.
OTP 27 will have a json module so it might make sense.

CREATE TEMPORARY TABLE j (
    id SERIAL PRIMARY KEY,
    name varchar(10)
);

INSERT INTO j (name) VALUES ('n1');
INSERT INTO j (name) VALUES ('n2');

SELECT json_agg(json_build_array(id, name)) FROM j;
pgo:query(<<"SELECT json_agg(json_build_array(id, name)) FROM j;">>).
#{command => select,
  rows => [{<<"[[1, \"n1\"], [2, \"n2\"]]">>}],
  num_rows => 1}

I can't use array_agg instead of json_agg because arrays support only single data type.

SELECT array_agg(ARRAY[id, name]) FROM j;
ERROR:  ARRAY types integer and character varying cannot be matched
@tsloughter
Copy link
Collaborator

oooh, I hadn't even thought of that use case for otp-27's json yet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants