Wpis z mikrobloga

Mam taki kod SQL:

with x as (select -1 stat)
select * from {tabela zawierająca kolumne status - wartości intowe m.in 1,2,100}
where status in

(
-- select (
case
when (select stat from x) = -1 then (select s from unnest(array[1,2]) s)
else (select stat from x)
end
-- )::regclass

)

order by id asc
limit 10

Jak w with dam żeby stat = (jakikolwiek int) to filtruje prawidłowo, jeżeli dam -1 to dostaję błąd ERROR: more than one row returned by a subquery used as an expression. Jak do klauzuli IN "dostarczyć" wartości z unnest(array) ?

#programowanie #postgresql #sql
  • 3
  • Odpowiedz