sql - PostgreSQL function execute query -
i want run sql query if condition met, following error:
error: separate $ chain unfinished in or near «$func$
my sql query is:
create or replace function myfunc() returns table(dateticket date, timeticket time, userid integer, my_all bigint) $func$ begin if (select count(distinct(dateticket)) tickets) = 1 return query execute 'select t.* (select distinct on (userid) dateticket, timeticket, userid, count(*) on (partition userid) my_all tickets t order userid, dateticket, timeticket) t order my_all, dateticket, timeticket'; else return query execute 'select t.* (select distinct on (userid) dateticket, timeticket, userid, count(*) on (partition userid) my_all tickets t order userid, dateticket, timeticket) t order my_all desc, dateticket desc, timeticket desc'; end if; end; $$ language plpgsql;
the error not condition or in function itself, syntax of function creation. start function definition $func$
, end $$
. not work.
change $func$
$$
fix syntax.
Comments
Post a Comment