Thank you for the answer. It works as expected.
But I realized that it will not solve my original problem I have in mind. 
Actually, I'm tryting to come up with some more or less ANSI compliant 
solution for the following issue:

I have two (or more) columns in database that represents the state of some 
single complex object. Taking an example from above, let's imagine that 
"bar" and "baz" are parts of one object. In case of "foo" contains scalar 
value (not collection) of the object, both columns "bar" and "baz" will 
have scalar types (not array):






*create table foo (  id varchar(256) primary key,  bar integer,  baz 
varchar(256));*
and I can select using following query:

*select * from foo where bar = ... and baz = ...*

But in case of "foo" contains collection of the this objects, both columns 
"bar" and "baz" become array types:






*create table foo (  id varchar(256) primary key,  bar integer array,  baz 
varchar(256) array);*
and if I select using following query:

*select * from foo where ... = any(bar) and ... = any(baz)*

it will give me false matches, as I need to compare only values from both 
arrays of the same ordinality.

While unnest in H2 supports unnesting of multiple arrays, it is impossible 
to use arrays taken from the currently selected row (it seems it is unable 
to reference columns of outside query from unnest finction). like this:

*select * from foo where exists (select 1 from unnest ((select bar from foo 
where id = foo.id), (select baz from foo where id = foo.id)) as e(e1, e2) 
where e1 = '...' and e2 = '...')*

In PostgreSQL referencing columns of curretly selected row from unnest is 
possible though. As well as it supports more clean way, allowing to use 
column references directly instead of array expressions within the unnest 
function:

*select * from foo where exists (select 1 from unnest (bar, baz) as e(e1, 
e2) where e1 = '...' and e2 = '...')*

BTW, Is there are any plans to support latest?

Thanks!

With respect,
Artem
On Sunday, September 17, 2023 at 12:10:08 PM UTC+9 Evgenij Ryazanov wrote:

> Hello!
>
> Yes, it is possible, but with valid SQL only.
>
> Subqueries must be enclosed in parentheses, all your queries are 
> incorrect. Valid queries are
>
> select * from unnest((select bar from foo));
> select * from unnest((select baz from foo));
> select * from unnest((select bar from foo), (select baz from foo));
>
> In some cases H2 allows subqueries without parentheses due to historic 
> reasons, but this undocumented syntax was implemented very inconsistently 
> and actually it isn't possible to implement it in reliable way due to 
> syntax conflicts. Don't use it, it is not supported and it may not work in 
> future versions of H2 in places where it works in 2.2.222.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/2ca391cf-6ec7-4070-9f56-b465a7f082c3n%40googlegroups.com.

Reply via email to