pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
autocommit for multi call store procedure
6+ messages / 4 participants
[nested] [flat]

* autocommit for multi call store procedure
@ 2021-09-16 07:36 Trang Le <trang.le@evizi.com>
  2021-09-16 07:38 ` Re: autocommit for multi call store procedure Ninad Shah <nshah.postgres@gmail.com>
  2021-09-16 14:21 ` Re: autocommit for multi call store procedure Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Trang Le @ 2021-09-16 07:36 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi guys,

I am using pgadmin4 to interact with Postgres database. For now I would
like to run 2 store procedure (those have commit statement in begin end
block). I enable autocommit and run call 2 store procedures at the same
time. However, there is an error with invalid transaction termination.

Could you help me on this issue?

Thanks,
Trang

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: autocommit for multi call store procedure
  2021-09-16 07:36 autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
@ 2021-09-16 07:38 ` Ninad Shah <nshah.postgres@gmail.com>
  2021-09-17 01:32   ` Fwd: autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Ninad Shah @ 2021-09-16 07:38 UTC (permalink / raw)
  To: Trang Le <trang.le@evizi.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Have you used an EXCEPTION block in the procedure?


Regards,
Ninad Shah

On Thu, 16 Sept 2021 at 13:06, Trang Le <trang.le@evizi.com> wrote:

> Hi guys,
>
> I am using pgadmin4 to interact with Postgres database. For now I would
> like to run 2 store procedure (those have commit statement in begin end
> block). I enable autocommit and run call 2 store procedures at the same
> time. However, there is an error with invalid transaction termination.
>
> Could you help me on this issue?
>
> Thanks,
> Trang
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Fwd: autocommit for multi call store procedure
  2021-09-16 07:36 autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
  2021-09-16 07:38 ` Re: autocommit for multi call store procedure Ninad Shah <nshah.postgres@gmail.com>
@ 2021-09-17 01:32   ` Trang Le <trang.le@evizi.com>
  2021-09-17 02:16     ` Re: autocommit for multi call store procedure David G. Johnston <david.g.johnston@gmail.com>
  2021-09-17 15:29     ` Re: Fwd: autocommit for multi call store procedure Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Trang Le @ 2021-09-17 01:32 UTC (permalink / raw)
  To: adrian.klaver@aklaver.com; +Cc: Ninad Shah <nshah.postgres@gmail.com>; pgsql-general@lists.postgresql.org

Hi Adrian,

I am processing this issue with Ninad.

Could you double check it?

Regards,
Trang

---------- Forwarded message ---------
From: Trang Le <trang.le@evizi.com>
Date: Fri, Sep 17, 2021 at 8:19 AM
Subject: Re: autocommit for multi call store procedure
To: Ninad Shah <nshah.postgres@gmail.com>


Hi Ninad,

Thanks for your sharing.

It's weird I can run in pgadmin4.

call PRC_ADDRESS_DS_TEST(); call PRC_ADDRESS_DS_TEST1();

[image: image.png]

Could you check it in pgadmin4?

Regard,
Trang

On Fri, Sep 17, 2021 at 12:20 AM Ninad Shah <nshah.postgres@gmail.com>
wrote:

> Hi Trang,
>
> The way you are executing It invokes functions sequentially. test1 will be
> executed first then test2.
>
> And yes, it works for me.
>
> postgres=# call transaction_test1(); call transaction_test2();
> CALL
> CALL
>
> In your case, you are facing the issue with the first call statement.
> Kindly check your version.
>
>
> Regards,
> Ninad Shah
>
> On Thu, 16 Sept 2021 at 15:29, Trang Le <trang.le@evizi.com> wrote:
>
>> Hi Ninah,
>>
>> Could you please run those queries at the same time?
>>
>> call transaction_test1();
>> call transaction_test2();
>>
>> I run in new windows
>>
>> [image: image.png]
>>
>> Regards,
>> Trang
>>
>> On Thu, Sep 16, 2021 at 4:53 PM Ninad Shah <nshah.postgres@gmail.com>
>> wrote:
>>
>>> Hi Trang,
>>>
>>> I tried it on version 13.3, and both the cases work as expected. Not
>>> only that but also by applying different variations in the procedure, it
>>> delivers desired results.
>>>
>>> *Case 1:*
>>>
>>> Do not use the call statement inside a procedure, rather just put simple
>>> INSERT statements followed by COMMIT, and it works as expected.
>>>
>>> postgres=# CREATE or replace PROCEDURE transaction_test3()
>>> postgres-# LANGUAGE plpgsql
>>> postgres-# AS $$
>>> postgres$# DECLARE
>>> postgres$#     r RECORD;
>>> postgres$# BEGIN
>>> postgres$#     INSERT INTO test_table VALUES (1, 'test1');
>>> postgres$#     INSERT INTO test_table VALUES (2, 'test2');
>>> postgres$#     COMMIT;
>>> postgres$# END;
>>> postgres$# $$;
>>> CREATE PROCEDURE
>>> postgres=#
>>> postgres=#
>>> postgres=# call transaction_test3();
>>> CALL
>>>
>>> *Case 2:*
>>>
>>> Use 2 call statements inside a nested BEGIN block followed by a COMMIT
>>> statement. This also works as expected.
>>>
>>> postgres=# CREATE or replace PROCEDURE transaction_test4()
>>> postgres-# LANGUAGE plpgsql
>>> postgres-# AS $$
>>> postgres$# DECLARE
>>> postgres$#     r RECORD;
>>> postgres$# BEGIN
>>> postgres$#     BEGIN
>>> postgres$#         call transaction_test1();
>>> postgres$#         call transaction_test2();
>>> postgres$#     COMMIT;
>>> postgres$#     END;
>>> postgres$# END;
>>> postgres$# $$;
>>> CREATE PROCEDURE
>>> postgres=#
>>> postgres=#
>>> postgres=# call transaction_test4();
>>> CALL
>>>
>>> Additionally, in all the cases, data is getting inserted into a test
>>> table.
>>>
>>> Kindly verify what version you are using?
>>>
>>>
>>> Regards,
>>> Ninad Shah
>>>
>>>
>>>
>>>
>>> On Thu, 16 Sept 2021 at 14:59, Trang Le <trang.le@evizi.com> wrote:
>>>
>>>> Hi Ninah,
>>>>
>>>> I already double checked with this case, it has the same problem.
>>>>
>>>> Could you please double check the attached file?
>>>>
>>>> Regards,
>>>> Trang
>>>>
>>>> On Thu, Sep 16, 2021 at 4:20 PM Ninad Shah <nshah.postgres@gmail.com>
>>>> wrote:
>>>>
>>>>> I saw some examples where COMMIT statements are part of FOR loops.
>>>>>
>>>>> Would you try using a loop?
>>>>>
>>>>>
>>>>> Regards,
>>>>> Ninad Shah
>>>>>
>>>>>
>>>>> On Thu, 16 Sept 2021 at 13:12, Trang Le <trang.le@evizi.com> wrote:
>>>>>
>>>>>> No, I leaved exception to sub-block. So it does not effect. I
>>>>>> committed in end of outer block and inside exception
>>>>>>
>>>>>> This is my query
>>>>>>
>>>>>> CREATE OR REPLACE PROCEDURE mdm.prc_address_ds_test(
>>>>>> )
>>>>>> LANGUAGE 'plpgsql'
>>>>>> AS $BODY$
>>>>>> BEGIN
>>>>>> CALL mdm.prc_log_job(v_job_id, v_cnt, v_job_desc, v_trx_type, 0,
>>>>>> v_start_ts);
>>>>>> BEGIN
>>>>>> v_cnt := v_cnt + 1;
>>>>>> v_start_ts := clock_timestamp();
>>>>>> v_job_desc := 'Insert records in address_ds test';
>>>>>> v_trx_type := 'I';
>>>>>> GET DIAGNOSTICS sql$rowcount = ROW_COUNT;
>>>>>> CALL mdm.prc_log_job(v_job_id, v_cnt, v_job_desc, v_trx_type,
>>>>>> sql$rowcount, v_start_ts);
>>>>>> EXCEPTION
>>>>>> WHEN others THEN
>>>>>> v_cnt := v_cnt + 1;
>>>>>> GET DIAGNOSTICS sql$rowcount = ROW_COUNT;
>>>>>> GET STACKED DIAGNOSTICS aws$frmt_err_bcktrc = PG_EXCEPTION_CONTEXT;
>>>>>> begin
>>>>>> CALL mdm.prc_log_job(v_job_id, v_cnt, v_job_desc, v_trx_type,
>>>>>> sql$rowcount::bigint, v_start_ts, substring(aws$frmt_err_bcktrc, 0, 4000));
>>>>>> commit;
>>>>>> end;
>>>>>> RAISE USING hint = -20101, message = aws$frmt_err_bcktrc, detail =
>>>>>> 'User-defined exception';
>>>>>> END;
>>>>>> CALL mdm.prc_log_job(job_id => v_job_id, job_id_seq_num => v_cnt,
>>>>>> job_trx_type => NULL, job_trx_cnt => NULL::bigint,
>>>>>>   job_desc => CONCAT('END JOB: ', v_job_nme)::character varying,
>>>>>> job_start_ts => v_start_ts);
>>>>>> commit;
>>>>>> END;
>>>>>> $BODY$;
>>>>>>
>>>>>> On Thu, Sep 16, 2021 at 2:38 PM Ninad Shah <nshah.postgres@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Have you used an EXCEPTION block in the procedure?
>>>>>>>
>>>>>>>
>>>>>>> Regards,
>>>>>>> Ninad Shah
>>>>>>>
>>>>>>> On Thu, 16 Sept 2021 at 13:06, Trang Le <trang.le@evizi.com> wrote:
>>>>>>>
>>>>>>>> Hi guys,
>>>>>>>>
>>>>>>>> I am using pgadmin4 to interact with Postgres database. For now I
>>>>>>>> would like to run 2 store procedure (those have commit statement in begin
>>>>>>>> end block). I enable autocommit and run call 2 store procedures at the same
>>>>>>>> time. However, there is an error with invalid transaction termination.
>>>>>>>>
>>>>>>>> Could you help me on this issue?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Trang
>>>>>>>>
>>>>>>>

Attachments:

image.png (image/png, 190.7K) download view image
image.png (image/png, 25.8K) download view image
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: autocommit for multi call store procedure
  2021-09-16 07:36 autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
  2021-09-16 07:38 ` Re: autocommit for multi call store procedure Ninad Shah <nshah.postgres@gmail.com>
  2021-09-17 01:32   ` Fwd: autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
@ 2021-09-17 02:16     ` David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: David G. Johnston @ 2021-09-17 02:16 UTC (permalink / raw)
  To: Trang Le <trang.le@evizi.com>; +Cc: adrian.klaver@aklaver.com <adrian.klaver@aklaver.com>; Ninad Shah <nshah.postgres@gmail.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On Thursday, September 16, 2021, Trang Le <trang.le@evizi.com> wrote
>
>
> Could you double check it?
>

We’re testing your failing code, not that PostgreSQL is working as
intended.  Suggest you get rid of all the stuff that doesn’t produce errors
and focus on trying to supply a minimal script that produces the unexpected
error.  Then send that as a single email, probably with an attachment and
some explanations.

David J.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Fwd: autocommit for multi call store procedure
  2021-09-16 07:36 autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
  2021-09-16 07:38 ` Re: autocommit for multi call store procedure Ninad Shah <nshah.postgres@gmail.com>
  2021-09-17 01:32   ` Fwd: autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
@ 2021-09-17 15:29     ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Adrian Klaver @ 2021-09-17 15:29 UTC (permalink / raw)
  To: Trang Le <trang.le@evizi.com>; +Cc: Ninad Shah <nshah.postgres@gmail.com>; pgsql-general@lists.postgresql.org

On 9/16/21 6:32 PM, Trang Le wrote:
> Hi Adrian,
> 
> I am processing this issue with Ninad.
> 
> Could you double check it?

I have no idea what the forwarded message was showing. Too many changes 
in code. As David suggested reduce this down to a simple test case that 
demonstrates your issue.

> 
> Regards,
> Trang
> 



-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: autocommit for multi call store procedure
  2021-09-16 07:36 autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
@ 2021-09-16 14:21 ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Adrian Klaver @ 2021-09-16 14:21 UTC (permalink / raw)
  To: Trang Le <trang.le@evizi.com>; pgsql-general@lists.postgresql.org

On 9/16/21 12:36 AM, Trang Le wrote:
> Hi guys,
> 
> I am using pgadmin4 to interact with Postgres database. For now I would 
> like to run 2 store procedure (those have commit statement in begin end 
> block). I enable autocommit and run call 2 store procedures at the same 
> time. However, there is an error with invalid transaction termination.
> 
> Could you help me on this issue?

Maybe but will need to see:

1) The content of the procedures.

2) The manner in which they are called.

3) The actual complete error message.

> 
> Thanks,
> Trang


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2021-09-17 15:29 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16 07:36 autocommit for multi call store procedure Trang Le <trang.le@evizi.com>
2021-09-16 07:38 ` Ninad Shah <nshah.postgres@gmail.com>
2021-09-17 01:32   ` Trang Le <trang.le@evizi.com>
2021-09-17 02:16     ` David G. Johnston <david.g.johnston@gmail.com>
2021-09-17 15:29     ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-09-16 14:21 ` Adrian Klaver <adrian.klaver@aklaver.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox