From: Milen A. Radev <milen@radev.net>
To: pgsql-sql@postgresql.org
Subject: Re: Variable number or arguments to a function possible?
Date: Sat, 25 Apr 2009 06:08:25 +0300
Message-ID: <gstur8$22b$1@ger.gmane.org> (raw)
In-Reply-To: <08F9706F-C603-46A2-8D42-5799D700DCE7@ruprecht.org>
References: <08F9706F-C603-46A2-8D42-5799D700DCE7@ruprecht.org>
Chris Ruprecht написа:
> Hello everybody,
>
> Is it possible to create a function that can take a variable number of
> arguments?
> I would like to write a function that creates a new record in the
> database. Based on what I send it, it should create a record in the
> appropriate table.
>
> Simple pseudo-code example:
>
> ... function create_record( varchar [,...] ) returns bigint as
>
> if $1 = 'state' then insert into state ( $2, $3 ) // $2 being state
> name, and $3 state code
> if $1 = 'phone' then insert into phone ( $4::bigint, $2, $3 ) // $2 =
> phone number, $3 = phone type, $4 = id of person that ownes the phone
>
> and so on.
>
> How would I declare that function?
You'll be able to do that (or something similar) in the next, still
in beta, version 8.4
(http://www.postgresql.org/docs/8.4/static/xfunc-sql.html#XFUNC-SQL-VARIADIC-FUNCTIONS),
but right now the closest to what you want is function overloading
(http://www.postgresql.org/docs/current/static/xfunc-overload.html).
--
Milen A. Radev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: milen@radev.net
Subject: Re: Variable number or arguments to a function possible?
In-Reply-To: <gstur8$22b$1@ger.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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