@@ -204,3 +204,114 @@ func testNorthwindJoinEverythingJson(t require.TestingT) {
204204 //testutils.SaveJSONFile(dest, "./testdata/results/postgres/northwind-all2.json")
205205 testutils .AssertJSONFile (t , dest , "./testdata/results/postgres/northwind-all.json" )
206206}
207+
208+ func TestColumnListFrom (t * testing.T ) {
209+
210+ toOrderBy := map [string ]bool {
211+ "city" : true ,
212+ "region" : true ,
213+ "postal_code" : true ,
214+ }
215+
216+ subQuery := SELECT (
217+ Customers .AllColumns ,
218+ ).FROM (
219+ Customers ,
220+ ).AsTable ("subQuery" )
221+
222+ var orderBy []OrderByClause
223+
224+ for _ , column := range Customers .AllColumns .From (subQuery ) {
225+ if toOrderBy [column .Name ()] {
226+ orderBy = append (orderBy , column .ASC ())
227+ }
228+ }
229+
230+ stmt := SELECT (
231+ subQuery .AllColumns (),
232+ ).FROM (
233+ subQuery ,
234+ ).ORDER_BY (
235+ orderBy ... ,
236+ ).LIMIT (3 )
237+
238+ testutils .AssertDebugStatementSql (t , stmt , `
239+ SELECT "subQuery"."customers.customer_id" AS "customers.customer_id",
240+ "subQuery"."customers.company_name" AS "customers.company_name",
241+ "subQuery"."customers.contact_name" AS "customers.contact_name",
242+ "subQuery"."customers.contact_title" AS "customers.contact_title",
243+ "subQuery"."customers.address" AS "customers.address",
244+ "subQuery"."customers.city" AS "customers.city",
245+ "subQuery"."customers.region" AS "customers.region",
246+ "subQuery"."customers.postal_code" AS "customers.postal_code",
247+ "subQuery"."customers.country" AS "customers.country",
248+ "subQuery"."customers.phone" AS "customers.phone",
249+ "subQuery"."customers.fax" AS "customers.fax"
250+ FROM (
251+ SELECT customers.customer_id AS "customers.customer_id",
252+ customers.company_name AS "customers.company_name",
253+ customers.contact_name AS "customers.contact_name",
254+ customers.contact_title AS "customers.contact_title",
255+ customers.address AS "customers.address",
256+ customers.city AS "customers.city",
257+ customers.region AS "customers.region",
258+ customers.postal_code AS "customers.postal_code",
259+ customers.country AS "customers.country",
260+ customers.phone AS "customers.phone",
261+ customers.fax AS "customers.fax"
262+ FROM northwind.customers
263+ ) AS "subQuery"
264+ ORDER BY "subQuery"."customers.city" ASC, "subQuery"."customers.region" ASC, "subQuery"."customers.postal_code" ASC
265+ LIMIT 3;
266+ ` )
267+
268+ var dest []model.Customers
269+
270+ err := stmt .Query (db , & dest )
271+ require .NoError (t , err )
272+
273+ testutils .AssertJSON (t , dest , `
274+ [
275+ {
276+ "CustomerID": "DRACD",
277+ "CompanyName": "Drachenblut Delikatessen",
278+ "ContactName": "Sven Ottlieb",
279+ "ContactTitle": "Order Administrator",
280+ "Address": "Walserweg 21",
281+ "City": "Aachen",
282+ "Region": null,
283+ "PostalCode": "52066",
284+ "Country": "Germany",
285+ "Phone": "0241-039123",
286+ "Fax": "0241-059428"
287+ },
288+ {
289+ "CustomerID": "RATTC",
290+ "CompanyName": "Rattlesnake Canyon Grocery",
291+ "ContactName": "Paula Wilson",
292+ "ContactTitle": "Assistant Sales Representative",
293+ "Address": "2817 Milton Dr.",
294+ "City": "Albuquerque",
295+ "Region": "NM",
296+ "PostalCode": "87110",
297+ "Country": "USA",
298+ "Phone": "(505) 555-5939",
299+ "Fax": "(505) 555-3620"
300+ },
301+ {
302+ "CustomerID": "OLDWO",
303+ "CompanyName": "Old World Delicatessen",
304+ "ContactName": "Rene Phillips",
305+ "ContactTitle": "Sales Representative",
306+ "Address": "2743 Bering St.",
307+ "City": "Anchorage",
308+ "Region": "AK",
309+ "PostalCode": "99508",
310+ "Country": "USA",
311+ "Phone": "(907) 555-7584",
312+ "Fax": "(907) 555-2880"
313+ }
314+ ]
315+ ` )
316+
317+ }
0 commit comments