Re: Variable number or arguments to a function possible?

From: "Milen A(dot) Radev" <milen(at)radev(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Variable number or arguments to a function possible?
Date: 2009-04-25 03:08:25
Message-ID: gstur8$22b$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2009-04-25 03:09:38 Re: Variable number or arguments to a function possible?
Previous Message Chris Ruprecht 2009-04-25 02:04:54 Variable number or arguments to a function possible?