Ordering a query result set by an array in PostgreSQL

Hello

I created a PostgreSQL function if(boolean, anyelement, anyelement) to can use the IF clause in Phalcon. If there are less than or equal to 18 if statements the query is success else throws error:

Phalcon\Mvc\Model\Exception[0]: Syntax error, unexpected token DOT, near to 'mmb_id = 1565, 18, IF (m.mmb_id = 1717, 19, IF (m.mmb_id = 1551, 20, IF (m.mmb_id = 1797, 21, IF (m.mmb_id = 1407, 22, IF (m.mmb_id = 1804, 23, IF (m.mmb_id = 1820, 24, IF (m.mmb_id = 1498, 25, IF (m.mmb_id = 1661, 26, IF (m.mmb_id = 1605, 27, IF (m.mmb_id = 1810, 28, IF (m.mmb_id = 1791, 29,29))))))))))))))))))))))))))))))', when parsing: SELECT [m].* FROM [Xyz\Models\Members] AS [m] INNER JOIN [Xyz\Models\Users] ON m.usr_id = Xyz\Models\Users.usr_id INNER JOIN [Xyz\Models\Offices] ON Xyz\Models\Offices.mmb_id = m.mmb_id WHERE (((((((m.mmb_id IN (:AP0:, :AP1:, :AP2:, :AP3:, :AP4:, :AP5:, :AP6:, :AP7:, :AP8:, :AP9:, :AP10:, :AP11:, :AP12:, :AP13:, :AP14:, :AP15:, :AP16:, :AP17:, :AP18:, :AP19:, :AP20:, :AP21:, :AP22:, :AP23:, :AP24:, :AP25:, :AP26:, :AP27:, :AP28:, :AP29:)) AND (Xyz\Models\Offices.cnt_id = :cntid:)) AND (usr_is_active = "t")) AND (usr_is_acknowledged = "t")) AND (mmb_is_active = "t")) AND (mmb_is_acknowledged = "t")) AND (mmb_is_deleted = "f")) AND (mmb_expires_tstamp >= "2016-05-04 14:42:06") GROUP BY m.mmb_id ORDER BY IF (m.mmb_id = 1019, 0, IF (m.mmb_id = 1011, 1, IF (m.mmb_id = 1779, 2, IF (m.mmb_id = 1079, 3, IF (m.mmb_id = 1815, 4, IF (m.mmb_id = 1424, 5, IF (m.mmb_id = 1788, 6, IF (m.mmb_id = 1336, 7, IF (m.mmb_id = 1216, 8, IF (m.mmb_id = 1166, 9, IF (m.mmb_id = 1008, 10, IF (m.mmb_id = 1151, 11, IF (m.mmb_id = 1476, 12, IF (m.mmb_id = 1775, 13, IF (m.mmb_id = 1754, 14, IF (m.mmb_id = 1031, 15, IF (m.mmb_id = 1876, 16, IF (m.mmb_id = 1064, 17, IF (m.mmb_id = 1565, 18, IF (m.mmb_id = 1717, 19, IF (m.mmb_id = 1551, 20, IF (m.mmb_id = 1797, 21, IF (m.mmb_id = 1407, 22, IF (m.mmb_id = 1804, 23, IF (m.mmb_id = 1820, 24, IF (m.mmb_id = 1498, 25, IF (m.mmb_id = 1661, 26, IF (m.mmb_id = 1605, 27, IF (m.mmb_id = 1810, 28, IF (m.mmb_id = 1791, 29,29))))))))))))))))))))))))))))))

And you sure there is alias with m ?



192

Yes, the query works. I tried in command line.