I have the query below to get the previous and next row of a struct with ID
Ecto.Adapters.SQL.query( Repo, """ SELECT * FROM ( SELECT lead(id) over (order by position ) as next, lag(id) over (order by position ) as prev, id, parent_id FROM my_table WHERE parent_id=$1 ) x WHERE $2 IN (id, next, prev) """, [parent_id, id] )
The query works as in pure SQL, but I’m particularly interested in retrieving
prev. Can someone help to convert to Ecto query DSL?