pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Create functions using a function
3+ messages / 3 participants
[nested] [flat]

* Create functions using a function
@ 2010-03-01 21:50  Gianvito Pio <pio.gianvito@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Gianvito Pio @ 2010-03-01 21:50 UTC (permalink / raw)
  To: pgsql-sql

Hi all,
is there a way to define functions and/or triggers in a function?

For example, can I create a function that takes an argument and defines a
function that has the name passed as argument to the first function?

Something like this .....

CREATE FUNCTION test (name varchar) RETURNS VOID AS $$
BEGIN
       CREATE FUNCTION name ( ) (here "name" should be expanded to the
variable content) RETURNS ....
        ...

END
$$

Is there a way to do this? Thanks

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

* Re: Create functions using a function
@ 2010-03-01 22:38  Petru Ghita <petrutz@venaver.info>
  parent: Gianvito Pio <pio.gianvito@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Petru Ghita @ 2010-03-01 22:38 UTC (permalink / raw)
  To: Gianvito Pio <pio.gianvito@gmail.com>; +Cc: pgsql-sql

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Yes, it's possible. Use EXECUTE.
There is one example under "Example 38-9. Porting a Procedure from
PL/SQL to PL/pgSQL"
http://www.postgresql.org/docs/8.4/static/plpgsql-porting.html

Also have look in:
http://www.postgresql.org/docs/8.2/static/plpgsql-statements.html

under "37.6.5. Executing Dynamic Commands"

Petru Ghita

Gianvito Pio wrote:
> Hi all, is there a way to define functions and/or triggers in a
> function?
>
> For example, can I create a function that takes an argument and
> defines a function that has the name passed as argument to the
> first function?
>
> Something like this .....
>
> CREATE FUNCTION test (name varchar) RETURNS VOID AS $$ BEGIN CREATE
>  FUNCTION name ( ) (here "name" should be expanded to the variable
> content) RETURNS .... ...
>
> END $$
>
> Is there a way to do this? Thanks
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
iEYEARECAAYFAkuMQdYACgkQt6IL6XzynQSjoQCffcPZ2W69uy3wpGlkhkraQm2a
p0IAnA+8njdC6nAdpdhaTg/M9QEohYVb
=/tvu
-----END PGP SIGNATURE-----




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

* Re: Create functions using a function
@ 2010-03-06 07:55  Jasen Betts <jasen@xnet.co.nz>
  parent: Gianvito Pio <pio.gianvito@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Jasen Betts @ 2010-03-06 07:55 UTC (permalink / raw)
  To: pgsql-sql

On 2010-03-01, Gianvito Pio <pio.gianvito@gmail.com> wrote:
> --001485f44fc07594a40480c43c01
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi all,
> is there a way to define functions and/or triggers in a function?

assuming plpgsql: execute

> For example, can I create a function that takes an argument and defines a
> function that has the name passed as argument to the first function?
>
> Something like this .....

 CREATE FUNCTION test (name text) RETURNS VOID AS $$
 BEGIN

   EXECUTE 'CREATE FUNCTION '||quote_ident(name)|| 
   ...
     
   
 END $$ LANGUAGE PLPGSQL;




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


end of thread, other threads:[~2010-03-06 07:55 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-03-01 21:50 Create functions using a function Gianvito Pio <pio.gianvito@gmail.com>
2010-03-01 22:38 ` Petru Ghita <petrutz@venaver.info>
2010-03-06 07:55 ` Jasen Betts <jasen@xnet.co.nz>

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