Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id C0C43636352 for ; Fri, 23 Oct 2009 15:11:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 42535-07 for ; Fri, 23 Oct 2009 18:10:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yw0-f198.google.com (mail-yw0-f198.google.com [209.85.211.198]) by mail.postgresql.org (Postfix) with ESMTP id C69F0636345 for ; Fri, 23 Oct 2009 15:10:49 -0300 (ADT) Received: by ywh36 with SMTP id 36so8655802ywh.15 for ; Fri, 23 Oct 2009 11:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=m3jbj0dgOCesa1cdCQAO7isKa+zHWv8YLrUyF3qpCSw=; b=lij0ck/iRCMXBkLmynNCQlHMx0m7I0gSlqLIl1GG5OgNIymYgfjeD4WY5HmJCFTJPq ekV/bC9V049kNj9umwBuKDzIDtCOvAvZBK9HQ+RCkpn8a+qKEgatdE7OPX1rDEsCzOQG kPcs4Fnbn6evdXACa6yxX9xhsnUXRJGjnEEDU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=m8PEY9c2T2jQWorrA+28I7tSd7anKcWFA6Di0FFLCB/JcgC5gfFyQ3Xd4S1S7eqpTr k6qp/BR1Ypk7mpZ928h2ZOWsTpHMngdDzQT3LYwqzqVdNge3uXNHsLw1VXgwB3S/Vm2I cGHrcfHUe0+45P5zBzu6jhsHVbnIWeW6/LkvQ= MIME-Version: 1.0 Received: by 10.150.45.34 with SMTP id s34mr18735938ybs.274.1256321448700; Fri, 23 Oct 2009 11:10:48 -0700 (PDT) In-Reply-To: References: Date: Fri, 23 Oct 2009 20:10:48 +0200 Message-ID: <162867790910231110y3e86a5a4o1584e1f4c97b0625@mail.gmail.com> Subject: Re: Table Valued Parameters From: Pavel Stehule To: Andrew Hall Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.582 tagged_above=-10 required=5 tests=AWL=0.017, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/120 X-Sequence-Number: 33319 Hello 2009/10/23 Andrew Hall : > Hi, > > I was wondering whether anybody would be able to advise me on how (if it = is > possible) to port some functionality from Oracle? > > This is just an example - in Oracle, I am able to do the following > Use refcursor, please. http://www.postgresql.org/docs/8.4/static/plpgsql-cursors.html Regards Pavel Stehule > -- > -- Create a data type which replicates the data structure of a single use= r > in my application. > -- I know that this can be done using PostgreSQL. > -- > > CREATE TYPE TY_APP_USER AS OBJECT > ( > =C2=A0 aur_id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 INT > , aur_username=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 VARCHAR2(30=C2=A0 CHAR) > , aur_is_account_enabled VARCHAR2(1=C2=A0=C2=A0 CHAR) > , aur_created_date=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 DATE > , aur_updated_date=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TIMESTAMP > ) > / > > -- > -- Create a data type which can store many instances of a single > 'TY_APP_USER' > -- [essentially this is a table valued data type]. An instance of this da= ta > type can be > -- created and populated by the client application [a java based one in m= y > case]. > -- > -- I can't find any reference to something > -- similar to this using postgreSQL. > -- > > CREATE TYPE TTY_APP_USER AS TABLE OF TY_APP_USER > / > > -- > -- Next define a stored procedure which can accept an instance of a > TTY_APP_USER data > -- type, and treat that instance as a table, for example ... > -- > > CREATE OR REPLACE PROCEDURE prAddUsers > ( > =C2=A0 p_in_users IN tty_app_user > ) > IS > BEGIN > > =C2=A0 INSERT > =C2=A0=C2=A0=C2=A0 INTO > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 users > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ( > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 aur_id > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_username > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_is_account_enabled > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_created_by > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_created_date > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ) > =C2=A0 SELECT > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 aur_id > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_username > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_is_account_enabled > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_created_by > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , aur_created_date > =C2=A0=C2=A0=C2=A0 FROM > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TABLE > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ( > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CAST > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ( > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = p_in_users AS tty_app_user > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ); > > END prUpdateUsers; > > My motivation for doing this is to reduce network round trips, instead of > having 1 call per record to be sent to the db, I can have 1 call passing = all > values which I wish to store in the database. > > Sending multiple records to the database as a result of a single form > submission is a requirement that arises frequently [the example is just > intended to demonstrate the principle!], and I would be grateful if anybo= dy > could help me to arrive at an optimal solution. > > Cheers, > > Andrew. > > > > > > > ________________________________ > Download Messenger onto your mobile for free. Learn more.