1

I am facing a problem while executing a Function written using PL/pgSQL. The problem that I am facing is that when I execute the function manually using pgAdmin, the functions gets executed and the data gets loaded into the destination table. But when I execute the same function using a scheduler which has been developed by our team to execute all the different kinds of functions and ETLs based on the requirements, the postgreSQL function executes but doesn't COMMIT the data into the table. If we give a COMMIT statement after the function execution statement, only then the data gets committed.

Can any one suggest me what could be the possible reason for this behaviour of the function which get committed while executing manually but not when executed in a scheduler?

I would be highly obliged if someone can help me with this at the earliest.

Thanks in advance.

1 Answer 1

4

By default, postgresql operates in autocommit mode. That means that each SQL statement you execute Is immediately committed. This is what happens when you execute command using tools such as pgadmin or psql, assuming you do not execute BEGIN first.

I am guessing your scheduler framework is executing BEGIN before starting your job and that it expects you to commit the work as part of the job.

Without knowing more details about the scheduler it is impossible to be more specific.

Sign up to request clarification or add additional context in comments.

2 Comments

I am passing this statement as a parameter to my scheduler which calls my PostgreSQL function. SELECT test();commit; There is no BEGIN statement. If I remove the commit; statement then the data does not get inserted into the table, but if I give that commit it inserts into it.
@YousufIbnAkhtarSultan for that to happen there must have been a BEGIN given on that database handle before your task gets run in the scheduler - maybe by a previous task? I cannot think of any other explanation. If you can enable statement logging then you will probably be able to see what is going on a little better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.