go-ozzo / ozzo-dbx

A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.
MIT License
636 stars 91 forks source link

How to use lateral with this package? #38

Closed lawzava closed 7 years ago

lawzava commented 7 years ago

I have a query: SELECT * FROM products p, LATERAL ( SELECT jsonb_agg( jsonb_build_object('location', jsonb_build_object('timestamp', locations.timestamp, 'lat', st_x(locations.point), 'lon', st_y(locations.point)) ) ) FROM locations WHERE locations.product_id = p.id ) t2 ( location )

I failed to find how it would look while using dbx.

qiangxue commented 7 years ago

There's no direct support for this. The simplest way is to use dbx.NewQuery and pass in the above SQL. If you want to use query builder, you may build the the SELECT queries and then combine them into the final SQL, although I don't quite recommend in this case.