skunk icon indicating copy to clipboard operation
skunk copied to clipboard

Support `select * from ...` where schema is not known at compile time

Open fdietze opened this issue 2 years ago • 3 comments

(originally asked on discord: https://discord.com/channels/632277896739946517/839844929877704785/977322704363479050)

I need to query a table where the schema is not known at compile time. That means I'd like to do a select * from dynamicTable and get an Array[String | null] for every row, which I can further process according to the types I know at runtime.

Low-level types in the array would also be ok, since I can cast them accordingly. But I need to know if a field is null or not.

So far in ScalaJS, it seems like I'm stuck with with pg-node and use their rowmode: 'array' feature (https://node-postgres.com/features/queries)

fdietze avatar May 23 '22 16:05 fdietze

The low-level protocol produces a List[Option[String]] which is what you want, but there's no way to get to it through the provided interfaces. It could be done by modifying Query to know that the result is dynamic in order to selectively bypass arity/type checking.

tpolecat avatar May 23 '22 16:05 tpolecat

That sounds sufficient, thank you!

How do we proceed? Is it something you can do quickly, or should I get my hands dirty?

fdietze avatar May 23 '22 17:05 fdietze

I think I'll approach this soon. What would be the rough steps to implement it?

fdietze avatar May 26 '22 23:05 fdietze