Convert JSON array result into JS array
Hello, I am running an SQL query that returns data in this format since it is a PG JSON array:
How can I convert such an array in PG format to a string array in JS? Or better yet is there any way that kysely can do that already internally?
15 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
That seems like a stringified normal postgres array and not a JSON array. You can't parse that as JSON.
Is the column type something like
json[]
? If so, remove the array. JSON can hold arrays.this is the query im running:
I want to get the data as an array of strings
I did it as a raw query since Im not sure how to query the table
information_schema.tables
wiht teh builder
even when I do it like this:
in that lower case I get type errors because the introspection does not pull information_schema.tables
but I get he same result still comes out as a stringified postgres array... 😕
this expression:
returns this:
tables: "{business,address,...}"
Which dialect are you using?
array_agg
doesn't create a JSON array. It creates a postgres array
The problem is that the dialect you are using doesn't parse arraysim using postgres
Kysely never touches the output data. It returns what the dialect and the underlying DB driver returns
But which dialect?
hmmm
Like which dialect class
let me confirm quick
how do you create the Kysely instance
I'm in Deno so its a custom dialect I presume
using the Deno postgres driver
Ok, so then I can't help you. Third party dialects do what they do
ok gotcha, but that helps me at least understand where the issue stems from 🙂
thanks for the help, and I'm liking Kysely very much!
UPDATE
Using
JSONB_AGG
instead of ARRAY_AGG
fixes the issue for meHey 👋
We have tests in place proving that our core PostgresDialect works in Deno.
the underlying node-postgres (pg) driver supports custom transformations of results by data type
GitHub
kysely/test/deno at master · kysely-org/kysely
A type-safe typescript SQL query builder. Contribute to kysely-org/kysely development by creating an account on GitHub.