Insert into wd_orderitem (count , id_dish , state , info , sn , id_order)values(1 , 1000000001 , 3 , ARRAY[ ROW(2,1000000001,CURRENT_TIMESTAMP(0))::info ] , (SELECT 1+(case when max(sn) ISNULL then 0 else max(sn) end) FROM wd_orderitem WHERE id_order