Note on scalar subquery syntax
От | Kevin Murphy |
---|---|
Тема | Note on scalar subquery syntax |
Дата | |
Msg-id | 42F0C94A.2030607@genome.chop.edu обсуждение исходный текст |
Ответы |
Re: Note on scalar subquery syntax
Re: Note on scalar subquery syntax |
Список | pgsql-general |
I thought this might be helpful in the future to other duffers such as myself. The following is my big contribution to the documentation of the use of scalar subqueries ;-): You have to wrap a scalar subquery in its own parentheses even where you might think it to be unnecessary, such as when the subquery is the sole argument to a function. As an example, I wrote a function to explode, or unpack, the elements of an array onto separate rows (its return type is SETOF whatever), but it took me a while to figure out how to use it effectively in queries. You have to use it like this: RIGHT--> select * from array_explode((select array_col from table1 where col2 = 'something')); Note the "extra" set of parentheses. These are crucial: the syntax is invalid without these, as in: WRONG--> select * from array_explode(select array_col from table1 where col2 = 'something'); And no, as mentioned in many archived list messages, you can NOT do the following, which is what a lot of people (including me) seem to try first: WRONG--> select array_explode(array_col) from table1 where col2 = 'something'); (The previous command results in the error message: "set-valued function called in context that cannot accept a set"). -Kevin Murphy
В списке pgsql-general по дате отправления: