citusdata / pg_cron

Run periodic jobs in PostgreSQL
PostgreSQL License
2.9k stars 195 forks source link

executing multiple statements in one job but logging only first statement's output #349

Open bsislow opened 3 months ago

bsislow commented 3 months ago

why do multiple statements in one job only log the first statement's output in cron.job_run_details in return_message?

example:

postgres=> create table a (b timestamp with time zone);
CREATE TABLE

postgres=> SELECT cron.schedule('* * * * *', $$select count(*) from a;insert into a select now();insert into a select now();$$);
 schedule
----------
       24
(1 row)

postgres=> select * from a;
               b
-------------------------------
 2024-08-20 14:10:00.068271+00
 2024-08-20 14:10:00.068271+00
(2 rows)

select * from cron.job_run_details order by end_time desc limit 1;
 jobid | runid | job_pid |  database   |  username   |                                     command                                     |  status   | return_message |          start_time
       |           end_time
-------+-------+---------+-------------+-------------+---------------------------------------------------------------------------------+-----------+----------------+------------------------
-------+-------------------------------
    25 |   664 |   11186 | postgres    | postgres    | select count(*) from a; insert into a select now(); insert into a select now(); | succeeded | INSERT 0 1     | 2024-08-20 14:10:00.010
36+00  | 2024-08-20 14:10:00.084913+00

we only see INSERT 0 1 here. this is restrictive when we're running a job that executes DELETEs that have child dependencies - in order, for example.

thanks.