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

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -