From: | Henry Drexler <alonup8tb(at)gmail(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: pgplsql - accessing rows from below or above. |
Date: | 2011-10-14 10:52:17 |
Message-ID: | CAAtgU9TbtVkiG7bbZZA0Gu50CZnEH3E=J+6jomSan4s5bKe7sQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Thu, Oct 13, 2011 at 5:57 PM, Henry Drexler <alonup8tb(at)gmail(dot)com> wrote:
>
> On Thu, Oct 13, 2011 at 5:10 PM, Henry Drexler <alonup8tb(at)gmail(dot)com>
> wrote:
>
>> Issue:
>
>
>
>
solved it.
I had to do a nested if then within the loop to get the iteration. (also I
forgot the u = u + 1; inside the loop to enable the iteration)
here is the solution.
create or replace function valueabovereal(node text) returns text language
plpgsql as $$
declare
t text;
total_count integer;
u integer;
begin
total_count := (
select
count(*)
from
(values('once'),('twice'),('three'),('four'),('five'),('six'),('threee'))
hello(node)
)
;
u := 1;
while u <= total_count loop
select into t
upon.node
from
(select
lag(hello.node,1) over (rows between unbounded preceding and unbounded
following) as node
from
(values('once'),('twice'),('three'),('four'),('five'),('six'),('threee'))
hello(node)
limit 1 offset u
) as upon ;
u = u + 1;
if t = $1 then exit;
end if;
end loop;
return t;
end;
$$
From | Date | Subject | |
---|---|---|---|
Next Message | Marcus Engene | 2011-10-14 15:07:07 | What could lock up pg_stat_activity |
Previous Message | Devrim GÜNDÜZ | 2011-10-14 06:50:34 | Re: Partitioning in PostgrSQL 9.04 |