Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id F08AF6332AC for ; Sat, 25 Apr 2009 00:08:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 60387-08 for ; Sat, 25 Apr 2009 00:08:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mail.postgresql.org (Postfix) with ESMTP id EEB67632982 for ; Sat, 25 Apr 2009 00:08:35 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1LxYFl-0004ep-Qi for pgsql-sql@postgresql.org; Sat, 25 Apr 2009 03:08:33 +0000 Received: from 77.70.61.39 ([77.70.61.39]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 25 Apr 2009 03:08:33 +0000 Received: from milen by 77.70.61.39 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 25 Apr 2009 03:08:33 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: "Milen A. Radev" Subject: Re: Variable number or arguments to a function possible? Date: Sat, 25 Apr 2009 06:08:25 +0300 Lines: 32 Message-ID: References: <08F9706F-C603-46A2-8D42-5799D700DCE7@ruprecht.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 77.70.61.39 User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) In-Reply-To: <08F9706F-C603-46A2-8D42-5799D700DCE7@ruprecht.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.599 tagged_above=0 required=5 tests=RCVD_IN_DNSWL_LOW=-1, RCVD_NUMERIC_HELO=2.599 X-Spam-Level: * X-Archive-Number: 200904/114 X-Sequence-Number: 32460 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