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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -