---
title: "Comment by Jeremy Bauman on \"Building a Queue System with Supabase and PostgreSQL\" | Hashnode"
description: "This section produces &quot;invalid SQL query&quot;, I can&#39;t seem to figure out why? I have been unable to get this process to work CREATE OR REPLACE FUNCTI"
url: "https://hashnode.com/posts/building-a-queue-system-with-supabase-and-postgresql/6491b48a3a9e67f9192111d8/comment/64dd14f49154427d760d219e"
---

[Discussion](https://hashnode.com/posts/building-a-queue-system-with-supabase-and-postgresql/6491b48a3a9e67f9192111d8)

Comment [Building a Queue System with Supabase and PostgreSQL](https://hashnode.com/posts/building-a-queue-system-with-supabase-and-postgresql/6491b48a3a9e67f9192111d8)

[Jeremy Bauman](https://hashnode.com/@jb110)

[Aug 16, 2023](https://hashnode.com/posts/building-a-queue-system-with-supabase-and-postgresql/6491b48a3a9e67f9192111d8/comment/64dd14f49154427d760d219e)

This section produces "invalid SQL query", I can't seem to figure out why? I have been unable to get this process to work

```
CREATE OR REPLACE FUNCTION schedule_jobs()
RETURNS VOID
AS $$
BEGIN
    -- Schedule retry job
    SELECT cron.schedule(
        'retry_failed_jobs',
        '*/10 * * * *', 
        $$ SELECT retry_failed_jobs(); $$
    );
    -- Schedule first job
    PERFORM cron.schedule(
        'process_current_jobs_if_unlocked_job_1',
        '* * * * *',
        $$ SELECT process_current_jobs_if_unlocked(); $$
    );
    -- Schedule second job with a 20-second delay
    PERFORM pg_sleep(20);
    PERFORM cron.schedule(
        'process_current_jobs_if_unlocked_job_2',
        '* * * * *',
        $$ SELECT process_current_jobs_if_unlocked(); $$
    );
    -- Schedule third job with another 20-second delay
    PERFORM pg_sleep(20);
    PERFORM cron.schedule(
        'process_current_jobs_if_unlocked_job_3',
        '* * * * *',
        $$ SELECT process_current_jobs_if_unlocked(); $$
    );
END;
$$ LANGUAGE plpgsql;
```

[Rodrigo Mansueli](https://hashnode.com/@mansueli)

[Aug 16, 2023](https://hashnode.com/posts/building-a-queue-system-with-supabase-and-postgresql/6491b48a3a9e67f9192111d8/comment/64dd14f49154427d760d219e#reply-64dd23ca4429385b92804dd5)

Sorry, a little oversight from me. If you change the $$ in the function or in each command with a different context it will work:

```
RETURNS VOID
AS $function$
BEGIN
(...)
$function$ LANGUAGE plpgsql;
```

Or on each command:

```
 PERFORM cron.schedule(
        'process_current_jobs_if_unlocked_job_3',
        '* * * * *',
        $command$ SELECT process_current_jobs_if_unlocked(); $command$
    );
```

I'll update the article to fix the example.
