我正在嘗試通過選擇查詢將日期添加到陣列中。
我收到此錯誤:
SQL 錯誤 [22P02]:錯誤:格式錯誤的陣列文字:“2021-04-02”
declare dateval date[];
begin
select days into dateval from holidays where days between '2021-01-01' and '2021-12-31' and city='NY';
然后我需要在 if 陳述句中比較這個陣列我在這個 dateval 陣列中的日期變數做一些事情或者去 else 那樣
uj5u.com熱心網友回復:
您需要將它們聚合到一個陣列中,以便能夠將它們存盤為一個:
select array_agg(days)
into dateval
from ...
uj5u.com熱心網友回復:
也許您不需要陣列,而是exists在您的if條件中使用和子查詢。
if my_date_var between '2021-01-01' and '2021-12-31' and exists
(
select from holidays
where my_date_var = days
and city='NY'
) then ...
或使用in(可能效率較低)
if my_date_var in
(
select days from holidays
where days between '2021-01-01' and '2021-12-31'
and city='NY'
) then ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/366059.html
標籤:数组 PostgreSQL的 日期 plpgsql
上一篇:如何在curl命令中使用日期變數
