i have table @ least "name" column , "ordinal_position" column. wish loop each row starting row user inputs. let's user inputs "john", , ordinal_position 6 (out of 10 total). how loop last 4 rows without using subquery? i've tried using "over()" window function doesn't seem work on offset part of query, , same offset takes numbers (as far know) not strings.
edit (in response klin):
insert foo(id,name,ordinal_position) values (default,'peter',1), (default,'james',2), (default,'freddy',3), (default,'mark',4), (default,'jack',5), (default,'john',6), (default,'will',7), (default,'robert',8), (default,'dave',9), (default,'michael',10);
so in for, since user inputed "john" want loop through will-michael. following without subquery:
select * foo order ordinal_position offset (select ordinal_position foo name='john');
unfortunately, have query table find ordinal_position
given name
. however, not use offset
. can in where
clause, large tables faster:
select * foo ordinal_position > (select ordinal_position foo name = 'john') order ordinal_position; id | name | ordinal_position ----+---------+------------------ 7 | | 7 8 | robert | 8 9 | dave | 9 10 | michael | 10 (4 rows)
Comments
Post a Comment