pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedCalling Procedure from another procedure in Postgres
4+ messages / 4 participants
[nested] [flat]
* Calling Procedure from another procedure in Postgres
@ 2020-12-02 10:20 Muthukumar.GK <muthankumar@gmail.com>
0 siblings, 3 replies; 4+ messages in thread
From: Muthukumar.GK @ 2020-12-02 10:20 UTC (permalink / raw)
To: pgsql-general
Hi team,
I need to call the procedure(not function) and insert the records into a
temporary table from another procedure in postgres. When executing the
procedure 'Sampleproc2',I got some below syntax error. Kindly let me know
whether postgres supports this functionality or any other way of calling
the procedure from another procedure.
CREATE OR REPLACE PROCEDURE SampleProc1()
as $$
declare
c1 refcursor:='result1';
begin
open c1 for
select approverid,assigntoid,effstdt,effenddtfrom tblApproverreassign;
end;
$$
language plpgsql;
-------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE SampleProc2()
as $$
declare c1 refcursor:='result1';
begin
CREATE TEMP TABLE TMPApproverAssign
( approverid VARCHAR(10),
assigntoid VARCHAR(10),
effstdt timestamptz,
effenddt timestamptz
) ON COMMIT DROP;
INSERT INTO TMPApproverAssign
*CALL SampleProc1(); *
open c1 for
select approverid,assigntoid,effstdt,effenddtfrom TMPApproverAssign;
end;
$$
language plpgsql;
---------------------------------------------------------------------------------------------
Error : syntax error at or near "CALL"
LINE 12 : ^CALL SampleProc1();
SQL state : 42601
Character:453
------------------------------------------------------------------
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Calling Procedure from another procedure in Postgres
@ 2020-12-02 10:34 Hemil Ruparel <hemilruparel2002@gmail.com>
parent: Muthukumar.GK <muthankumar@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Hemil Ruparel @ 2020-12-02 10:34 UTC (permalink / raw)
To: Muthukumar.GK <muthankumar@gmail.com>; +Cc: pgsql-general
insert into <table> is not valid
On Wed, Dec 2, 2020 at 3:50 PM Muthukumar.GK <muthankumar@gmail.com> wrote:
> Hi team,
>
> I need to call the procedure(not function) and insert the records into a
> temporary table from another procedure in postgres. When executing the
> procedure 'Sampleproc2',I got some below syntax error. Kindly let me know
> whether postgres supports this functionality or any other way of calling
> the procedure from another procedure.
>
> CREATE OR REPLACE PROCEDURE SampleProc1()
>
> as $$
>
> declare
>
> c1 refcursor:='result1';
>
> begin
>
> open c1 for
>
> select approverid,assigntoid,effstdt,effenddtfrom tblApproverreassign;
>
> end;
>
> $$
>
> language plpgsql;
>
>
> -------------------------------------------------------------------------------------------------------------
>
> CREATE OR REPLACE PROCEDURE SampleProc2()
>
> as $$
>
> declare c1 refcursor:='result1';
>
> begin
>
> CREATE TEMP TABLE TMPApproverAssign
>
> ( approverid VARCHAR(10),
>
> assigntoid VARCHAR(10),
>
> effstdt timestamptz,
>
> effenddt timestamptz
>
> ) ON COMMIT DROP;
>
>
>
> INSERT INTO TMPApproverAssign
>
> *CALL SampleProc1(); *
>
>
> open c1 for
>
> select approverid,assigntoid,effstdt,effenddtfrom TMPApproverAssign;
>
> end;
>
> $$
>
> language plpgsql;
>
>
> ---------------------------------------------------------------------------------------------
>
> Error : syntax error at or near "CALL"
>
> LINE 12 : ^CALL SampleProc1();
>
> SQL state : 42601
>
> Character:453
>
> ------------------------------------------------------------------
>
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Calling Procedure from another procedure in Postgres
@ 2020-12-02 10:39 Pavel Stehule <pavel.stehule@gmail.com>
parent: Muthukumar.GK <muthankumar@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Pavel Stehule @ 2020-12-02 10:39 UTC (permalink / raw)
To: Muthukumar.GK <muthankumar@gmail.com>; +Cc: pgsql-general
st 2. 12. 2020 v 11:20 odesílatel Muthukumar.GK <muthankumar@gmail.com>
napsal:
> Hi team,
>
> I need to call the procedure(not function) and insert the records into a
> temporary table from another procedure in postgres. When executing the
> procedure 'Sampleproc2',I got some below syntax error. Kindly let me know
> whether postgres supports this functionality or any other way of calling
> the procedure from another procedure.
>
> CREATE OR REPLACE PROCEDURE SampleProc1()
>
> as $$
>
> declare
>
> c1 refcursor:='result1';
>
> begin
>
> open c1 for
>
> select approverid,assigntoid,effstdt,effenddtfrom tblApproverreassign;
>
> end;
>
> $$
>
> language plpgsql;
>
>
> -------------------------------------------------------------------------------------------------------------
>
> CREATE OR REPLACE PROCEDURE SampleProc2()
>
> as $$
>
> declare c1 refcursor:='result1';
>
> begin
>
> CREATE TEMP TABLE TMPApproverAssign
>
> ( approverid VARCHAR(10),
>
> assigntoid VARCHAR(10),
>
> effstdt timestamptz,
>
> effenddt timestamptz
>
> ) ON COMMIT DROP;
>
>
>
> INSERT INTO TMPApproverAssign
>
> *CALL SampleProc1(); *
>
>
> open c1 for
>
> select approverid,assigntoid,effstdt,effenddtfrom TMPApproverAssign;
>
> end;
>
> $$
>
> language plpgsql;
>
>
> ---------------------------------------------------------------------------------------------
>
> Error : syntax error at or near "CALL"
>
> LINE 12 : ^CALL SampleProc1();
>
> SQL state : 42601
>
> Character:453
>
> ------------------------------------------------------------------
>
Procedures in Postgres cannot to returns tables, so INSERT INTO CALL is
unsupported
Regards
Pavel
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Calling Procedure from another procedure in Postgres
@ 2020-12-02 10:55 Thomas Kellerer <shammat@gmx.net>
parent: Muthukumar.GK <muthankumar@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Kellerer @ 2020-12-02 10:55 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org; +Cc: Muthukumar.GK <muthankumar@gmail.com>
Muthukumar.GK schrieb am 02.12.2020 um 11:20:
> I need to call the procedure(not function) and insert the records
> into a temporary table from another procedure in postgres. When
> executing the procedure 'Sampleproc2',I got some below syntax error.
> Kindly let me know whether postgres supports this functionality or
> any other way of calling the procedure from another procedure.
> CREATE OR REPLACE PROCEDURE SampleProc1()
> as $$
> declare
> c1 refcursor:='result1';
> begin
> open c1 for
> select approverid,assigntoid,effstdt,effenddtfrom tblApproverreassign;
> end;
> $$
> language plpgsql;
>
> INSERT INTO TMPApproverAssign
> *CALL SampleProc1(); *
You need to make sampleproc1 a set returning _function_, then you can do:
INSERT INTO TMPApproverAssign
select *
from sampleproc1();
Procedures aren't meant to return stuff, that's what functions are for.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2020-12-02 10:55 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 10:20 Calling Procedure from another procedure in Postgres Muthukumar.GK <muthankumar@gmail.com>
2020-12-02 10:34 ` Hemil Ruparel <hemilruparel2002@gmail.com>
2020-12-02 10:39 ` Pavel Stehule <pavel.stehule@gmail.com>
2020-12-02 10:55 ` Thomas Kellerer <shammat@gmx.net>
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