sql - Browse subcolumns, but discard some -
i have table (or view) in postgresql database , want following: query table , feed function in application subsequent n-tuples of rows query, satisfy condition. can n-tuple listing using cursor, don't know how condition checking on database level.
for example, query returns:
3 2 4 2 0 1 4 6 2
and want triples of numbers. here, be:
(2,4,2) (4,2,0) (4,6,2)
obviously, cannot discard odd numbers query result. instead using cursor, query returning arrays in similar manner acceptable solution, don't have idea how use them this.
of course, check @ application level, think it'd cleaner on database level. possible?
with window function lead()
(as mentioned @wildplasser):
select * ( select tbl_id, i1 , lead(i) on (order tbl_id) i2 , lead(i, 2) on (order tbl_id) i3 tbl ) sub i1%2 = 0 , i2%2 = 0 , i3%2 = 0;
there no natural order of rows - assuming want order tbl_id
in example.
%
.. modulo operator
Comments
Post a Comment