选择包含数组的行

huangapple go评论67阅读模式
英文:

Select row by array contains check

问题

我有一个类似的表格

CREATE TABLE table(
    name VARCHAR(100) NOT NULL,
    array INTEGER ARRAY NOT NULL
);

例如,如果我有以下行

name: test, array: [1, 2, 3]
name: test2, array: [663, 332, 334]

如何选择包含 332 在 array 中的行?该数组的长度可以是任意的,但不会为 null。

不幸的是,在 HSQLDB 数组方面没有太多的文档.. 我正在使用版本 2.5.1 和 Java JDBC。

英文:

I have a table like

CREATE TABLE table(
	name VARCHAR(100) NOT NULL,
	array INTEGER ARRAY NOT NULL
);

For example if I have the rows

name: test, array: [1, 2, 3]
name: test2, array: [663, 332, 334]

How can I select the row which contains 332 in array? The array can be of any length but never null.

Unfortunately there isn't much documentation on HSQLDB arrays.. I'm using version 2.5.1 with Java JDBC.

答案1

得分: 0

已解决。之前的方法调用引发了一个异常,阻止了实际异常的抛出。

SELECT * FROM table WHERE 332 IN ( UNNEST(array) )
英文:

Solved it. There was an exception caused by a previous method call which prevented the actual exception from throwing.

SELECT * FROM table WHERE 332 IN ( UNNEST(array) )

答案2

得分: -1

SELECT 332 IN UNNEST([663, 332, 334]) AS contains_value;

英文:
SELECT 332 IN UNNEST([663, 332, 334]) AS contains_value;

huangapple
  • 本文由 发表于 2020年10月23日 22:55:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/64502378.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定