我有以下查询:使用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