pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Call function with dynamic schema name 5+ messages / 3 participants [nested] [flat]
* Call function with dynamic schema name @ 2012-01-15 17:28 IlGenna <alessio.gennari78@gmail.com> 2012-01-15 17:33 ` Re: Call function with dynamic schema name Pavel Stehule <pavel.stehule@gmail.com> 0 siblings, 1 reply; 5+ messages in thread From: IlGenna @ 2012-01-15 17:28 UTC (permalink / raw) To: pgsql-sql Hi to everyone, I would like to use in my function (plpgsql or sql) dynamic schema name to execute query or to call other functions. For exemple in oracle is possible to excute query in this manner: SELECT * FROM &&SCHEMA_NAME..TABLE_NAME; Where I think &&SCHEMA_NAME. is a sessione variable. I found tath I can use dynamic SQL like this: execute 'select * from ' || schema_name || '.table_name'; However, I would like to know if exist any other system to use dynamic schema name more similiar to Oracle. Another pl language is also ok. Thank you very much. Alessio -- View this message in context: http://postgresql.1045698.n5.nabble.com/Call-function-with-dynamic-schema-name-tp5146721p5146721.htm... Sent from the PostgreSQL - sql mailing list archive at Nabble.com. ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Call function with dynamic schema name 2012-01-15 17:28 Call function with dynamic schema name IlGenna <alessio.gennari78@gmail.com> @ 2012-01-15 17:33 ` Pavel Stehule <pavel.stehule@gmail.com> 2012-01-15 17:37 ` Re: Call function with dynamic schema name IlGenna <alessio.gennari78@gmail.com> 0 siblings, 1 reply; 5+ messages in thread From: Pavel Stehule @ 2012-01-15 17:33 UTC (permalink / raw) To: IlGenna <alessio.gennari78@gmail.com>; +Cc: pgsql-sql Hello 2012/1/15 IlGenna <alessio.gennari78@gmail.com>: > Hi to everyone, > I would like to use in my function (plpgsql or sql) dynamic schema name to > execute query or to call other functions. > > For exemple in oracle is possible to excute query in this manner: > > > SELECT * FROM &&SCHEMA_NAME..TABLE_NAME; > > Where I think &&SCHEMA_NAME. is a sessione variable. > > I found tath I can use dynamic SQL like this: > > execute 'select * from ' || schema_name || '.table_name'; > > > However, I would like to know if exist any other system to use dynamic > schema name more similiar to Oracle. Another pl language is also ok. There are no similar way to Oracle. You can set a search_path variable, but you have to be careful, because cached plans in PL/pgSQL can do some issues, when function is called again with different search path. Regards Pavel Stehule > > > Thank you very much. > > > Alessio > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/Call-function-with-dynamic-schema-name-tp5146721p5146721.htm... > Sent from the PostgreSQL - sql mailing list archive at Nabble.com. > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Call function with dynamic schema name 2012-01-15 17:28 Call function with dynamic schema name IlGenna <alessio.gennari78@gmail.com> 2012-01-15 17:33 ` Re: Call function with dynamic schema name Pavel Stehule <pavel.stehule@gmail.com> @ 2012-01-15 17:37 ` IlGenna <alessio.gennari78@gmail.com> 2012-01-15 18:27 ` Re: Call function with dynamic schema name Pavel Stehule <pavel.stehule@gmail.com> 0 siblings, 1 reply; 5+ messages in thread From: IlGenna @ 2012-01-15 17:37 UTC (permalink / raw) To: pgsql-sql Can you provide me e little example plz? Thanks in advance. Alessio -- View this message in context: http://postgresql.1045698.n5.nabble.com/Call-function-with-dynamic-schema-name-tp5146721p5146739.htm... Sent from the PostgreSQL - sql mailing list archive at Nabble.com. ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Call function with dynamic schema name 2012-01-15 17:28 Call function with dynamic schema name IlGenna <alessio.gennari78@gmail.com> 2012-01-15 17:33 ` Re: Call function with dynamic schema name Pavel Stehule <pavel.stehule@gmail.com> 2012-01-15 17:37 ` Re: Call function with dynamic schema name IlGenna <alessio.gennari78@gmail.com> @ 2012-01-15 18:27 ` Pavel Stehule <pavel.stehule@gmail.com> 0 siblings, 0 replies; 5+ messages in thread From: Pavel Stehule @ 2012-01-15 18:27 UTC (permalink / raw) To: IlGenna <alessio.gennari78@gmail.com>; +Cc: pgsql-sql 2012/1/15 IlGenna <alessio.gennari78@gmail.com>: > Can you provide me e little example plz? CREATE SCHEMA s1; CREATE SCHEMA s2; CREATE TABLE s1.a1(a int); CREATE TABLE s2.a1(a int); CREATE OR REPLACE FUNCTION s1.fx1() RETURNS int AS $$ BEGIN RETURN (SELECT MAX(a) FROM s1.a1); END $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION s2.fx1() RETURNS int AS $$ BEGIN RETURN (SELECT MAX(a) FROM s2.a1); END $$ LANGUAGE plpgsql; SET search_path TO s1; SELECT fx1(); -- returns max from s1.a1; SET search_path TO s2; SELECT fx1(); -- returns max from s2.s1; Regards Pavel Stehule > > Thanks in advance. > > Alessio > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/Call-function-with-dynamic-schema-name-tp5146721p5146739.htm... > Sent from the PostgreSQL - sql mailing list archive at Nabble.com. > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Call function with dynamic schema name @ 2012-01-15 22:36 Misa Simic <misa.simic@gmail.com> 0 siblings, 0 replies; 5+ messages in thread From: Misa Simic @ 2012-01-15 22:36 UTC (permalink / raw) To: IlGenna <alessio.gennari78@gmail.com>; pgsql-sql You could take a look on EXECUTE command in plpgsql... Depends on concrete problem but should be very careful with dynamic SQL because of SQL injection potential risk... Kind Regards, Misa Sent from my Windows Phone From: IlGenna Sent: 15/01/2012 18:29 To: pgsql-sql@postgresql.org Subject: [SQL] Call function with dynamic schema name Hi to everyone, I would like to use in my function (plpgsql or sql) dynamic schema name to execute query or to call other functions. For exemple in oracle is possible to excute query in this manner: SELECT * FROM &&SCHEMA_NAME..TABLE_NAME; Where I think &&SCHEMA_NAME. is a sessione variable. I found tath I can use dynamic SQL like this: execute 'select * from ' || schema_name || '.table_name'; However, I would like to know if exist any other system to use dynamic schema name more similiar to Oracle. Another pl language is also ok. Thank you very much. Alessio -- View this message in context: http://postgresql.1045698.n5.nabble.com/Call-function-with-dynamic-schema-name-tp5146721p5146721.htm... Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2012-01-15 22:36 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2012-01-15 17:28 Call function with dynamic schema name IlGenna <alessio.gennari78@gmail.com> 2012-01-15 17:33 ` Pavel Stehule <pavel.stehule@gmail.com> 2012-01-15 17:37 ` IlGenna <alessio.gennari78@gmail.com> 2012-01-15 18:27 ` Pavel Stehule <pavel.stehule@gmail.com> 2012-01-15 22:36 Re: Call function with dynamic schema name Misa Simic <misa.simic@gmail.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