sea-query icon indicating copy to clipboard operation
sea-query copied to clipboard

Add ability to select from function

Open DDtKey opened this issue 2 years ago • 2 comments

Motivation

It's actually possible to select from function, at least this is fair for postgres (e.g: select * from custom_function()) Moreover, AWS Aurora uses this approach (e.g: aurora_replica_status() doc)

Proposed Solutions

I think the maintainers know the best way to do this. But perhaps it's possible to implement IntoTableRef for Func.
So the following code will work:

Query::select().from(Func::cust("my_func"))

In this approach, probably, make sense to rename trait IntoTableRef

DDtKey avatar Jul 29 '22 12:07 DDtKey

I think we have had TableRef::SubQuery i.e. from_subquery so that you can actually SELECT * from (SELECT custom_function())

Syntactically they are different, but I think they perform the same query.

tyt2y3 avatar Jul 30 '22 01:07 tyt2y3

It looks like workaround & probably it may affect the query execution plan 🤔

I mean it isn't restricted, so it make sense to add such ability to SeaQuery

DDtKey avatar Jul 30 '22 09:07 DDtKey

@DDtKey @tyt2y3 hello! I create PR.

ikrivosheev avatar Oct 15 '22 14:10 ikrivosheev