kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.85k stars 276 forks source link

Support function tables #1199

Closed spearmootz closed 4 weeks ago

spearmootz commented 4 weeks ago

example

select * from crosstab('select a,b,c from "table" inner join "table2" on "table1".x = "table2".y') as crosstabAlias

API sample proposal

selectFrom(({ fn, selectFrom }) => fn( "crosstab", selectFrom("table") .select([a, b, c]) .innerJoin("table2", "table1.x", "table2.y") .as("crosstabAlias") ) );

current workaround

selectFrom( sqlselect * from crosstab('select a,b,c from "table" inner join "table2" on "table1".x = "table2".y') as crosstabAlias).select`)....compile()

spearmootz commented 4 weeks ago

Why is this closed? Is it because it's implemented or just won't be?

koskimas commented 4 weeks ago

Because it won't be. That's a really niche feature that wouldn't have much use. Implementing that would also be extremely unsafe since it involves stringifying SQL without using parameters.