我需要一个 WHERE 子句来检查 IN 列表中的元组: (field1, field2) in (('1', 1), ('2 ', 2), ('3', 3))。这是 Postgres 中的有效 SQL。
方言:POSTGRES
jOOQ 版本:3.9.6
这种情况下正确的 jOOQ 语法是什么?
jOOQ 3.9 文档暗示这是可能的,但他们的示例只给出了 1 级:https://www.jooq.org/doc/3.9/manual/sql-building/conditional-expressions/in-predicate-degree-n/
这段代码给出了我正在寻找的近似值,但我无法获得 referenceOrderIdLineNumbers 的正确类型/数据,也无法获得 jOOQ 生成的正确 SQL。
Collection<Row2<String, Integer>> referenceOrderIdLineNumbers = ...
List<Object[]> rows = dsl.select(... , field("count(TABLE3)", Integer.class )
.from(Tables.TABLE1)
.join(Tables.TABLE2).on(Tables.TABLE2.PK1.eq(Tables.TABLE1.PK1))
.join(Tables.TABLE3).on(Tables.TABLE3.PK2.eq(Tables.TABLE2.PK2))
.where(
row(Tables.TABLE1.FIELD1, Tables.TABLE2.FIELD2) // <-- what to
.in(referenceOrderIdLineNumbers) // <-- do here??
)
.groupBy(...)
.fetch();
最佳答案
这是为我设计的。您可以尝试让 jOOQ 记录它为您生成的 SQL,并尝试直接针对您的数据库运行所述 SQL。
引用资料:
Collection<Row2<String, Integer>> field1Field2Collection = new LinkedList<>();
field1Field2Collection.add(row("1", 1));
field1Field2Collection.add(row("2", 2));
field1Field2Collection.add(row("3", 3));
Result<Record2<String, Integer>> field1Field2Results = dsl
.select(Tables.TABLE1.FIELD1, Tables.TABLE2.FIELD2)
.from(Tables.TABLE1)
.join(Tables.TABLE2).on(Tables.TABLE2.PK1.eq(Tables.TABLE1.PK1))
.where(row(Tables.TABLE1.FIELD1, Tables.TABLE2.FIELD2).in(field1Field2Collection))
.fetch();
关于java - jOOQ "IN"具有 N 次元组的谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56158155/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has
我看到这个错误:translationmissing:da.datetime.distance_in_words.about_x_hours我的语言环境文件:http://pastie.org/2944890我的看法:我已将其添加到我的application.rb中:config.i18n.load_path+=Dir[Rails.root.join('my','locales','*.{rb,yml}').to_s]config.i18n.default_locale=:da如果我删除I18配置,帮助程序会处理英语。更新:我在config/enviorments/devolpment
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que