postgresql - Postgre SQL incorrect syntaxt near If -
i'm trying create function it's having error @ if statement don't know what's problem it.
create function uspgetcountrylistwithpagenumber(in "pagenumber" integer, in "pagesize" integer, in "whereclause" text, in "orderby" text) returns setof getcountrylistitem $body$declare rowdata "getcountrylistitem"%rowtype; if $1 <> -1 , $2 <> -1 rowdata in loop execute 'select "countryid","countryname"' || 'from "mastercountry"' || $3 || $4 || 'limit' || $2 || 'offset' || ($1-1)*$2 return next rowdata; end loop; return; else rowdata in loop execute 'select "countryid","countryname"' || 'from "mastercountry"' || 'order "countryname" asc' return next rowdata; end loop; return; end if; end; $body$ language plpgsql immutable; alter function public.uspgetcountrylistwithpagenumber(in integer, in integer, in text, in text) owner postgres;
what want achieve custom paging .. want have function can take pagenumber,pagesize,whereclause,and orderbyclause
pagenumber=1 pagesize=10 whereclause=where 1=1 , countryname='india' orderbyclause=order countryname desc
above parameter values can helpful solving problem let me know if more information required. thank in advance..:p
you need begin
before first if
.
Comments
Post a Comment