我有以下查詢:使用Postgres的聚集功能與NHibernate
SELECT title_id, title, array_agg(g.name)
FROM title t
INNER JOIN title_genre tg USING(title_id)
INNER JOIN genre g USING (genre_id)
GROUP BY title_id, title
ORDER BY title_id
LIMIT 10
樣本輸出從該查詢:
5527;"The Burbs";"{Suspense,"Dark Humor & Black Comedies",Comedy,"Cult Comedies"}" 5528;"20,000 Leagues Under the Sea";"{"Family Adventures","Children & Family","Ages 5-7","Book Characters","Family Animation"}" 5529;"2001: A Space Odyssey";"{"Classic Sci-Fi & Fantasy","Sci-Fi Thrillers",Classics}" 5530;"2010: The Year We Make Contact";"{"Sci-Fi Dramas","Alien Sci-Fi","Sci-Fi & Fantasy","Dramas Based on Contemporary Literature","Psychological Thrillers","Dramas Based on the Book"}" 5531;"The 39 Steps";"{"Dramas Based on the Book","United Kingdom",Thrillers,"Espionage Thrillers","Dramas Based on Classic Literature",Suspense}" 5532;"4D Man";"{"Classic Sci-Fi & Fantasy","Sci-Fi & Fantasy","Sci-Fi Horror"}" 5533;"8 Seconds";"{Drama,"Romantic Dramas",Biographies,"Indie Dramas","Sports Dramas","Miscellaneous Sports","Sports Stories","Other Sports"}" 5534;"9 1/2 Weeks";"{"Steamy Romance",Romance,"Romantic Dramas"}" 5535;"About Last Night...";"{"Romantic Dramas","Romantic Comedies",Romance}" 5536;"Above the Law";"{"Action & Adventure","Action Thrillers","Martial Arts"}"
(1)如何創建圍繞ARRAY_AGG功能NHibernate的標準是什麼?我需要以任何方式擴展PostgreSQL方言以適應此? (2)我使用SQLite作爲我的集成測試數據庫和PostgreSQL作爲我的測試/產品數據庫。 SQLite沒有array_agg函數,但是有一個類似的group_concat函數。是否有可能設置一些東西,我可以在我的測試中使用SQLite,在test/prod中使用PostgreSQL?
(3)array_agg以數組形式返回數據。我在nhibernate.info上發現了一篇很好的文章,解釋瞭如何擴展NHibernate來處理PostgreSQL數組。我如何將其納入我的標準?例如,假設我想找到一個不屬於浪漫劇的戲劇類型的標題。
在此先感謝您的幫助!
我同意:隨着您在生產中使用,始終使用相同的環境來測試(和開發) – 2011-04-15 06:59:34