Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 60715633DD2 for ; Fri, 23 Oct 2009 15:32:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 43529-09 for ; Fri, 23 Oct 2009 18:32:39 +0000 (UTC) X-Greylist: from 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 D4DA0633A37 for ; Fri, 23 Oct 2009 15:32:38 -0300 (ADT) Received: by ywh36 with SMTP id 36so8678482ywh.15 for ; Fri, 23 Oct 2009 11:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=9IWOuqrLaKjfcK7EXxblHmsH8VKmDoygAeNQQGjqPAg=; b=qY1uHt4td0tPEhUelvoOosk/U/q2c6TL90jmCczllHM1s9HDkJlfDE0X9qGnMZxUMs yNsUjyYZFBXpyZI/vDjdAaAtj7vhyvA4yxCMUMSpn6ce/cVaDNGIDI/fxHt4XCZiz+7g 6NCCOb7I6x+EfQzwzVUwnSO0IVuqwuaMJIuqQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=DsQunmYpPb0CVD5dTHSuPDsLvFTLEG4CciwRHypTKTdoaUynUvPl1+d8RIeis6zS0a 5GRWhy+/0tKgdT7Gjgn023JhKDDXI0VIKwgwkAzWioHLh/JYoKPfNmsJrXO0ygiGeiCw Zw8lj7Wf7eVLYpYcWKiQNQeNU331puIqnVGsM= MIME-Version: 1.0 Received: by 10.150.163.10 with SMTP id l10mr18766067ybe.223.1256322757665; Fri, 23 Oct 2009 11:32:37 -0700 (PDT) In-Reply-To: References: <162867790910231110y3e86a5a4o1584e1f4c97b0625@mail.gmail.com> Date: Fri, 23 Oct 2009 20:32:37 +0200 X-Google-Sender-Auth: 0c3e0d4f24684337 Message-ID: <5a9699850910231132t58f36453o735a8287c7aed64c@mail.gmail.com> Subject: Re: FW: Table Valued Parameters From: Brian Modra To: Andrew Hall Cc: PostgreSQL Mailing List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/122 X-Sequence-Number: 33321 2009/10/23 Andrew Hall : > Hi Pavel, > > many thanks for the very prompt reply. > > I was under the impression that a refcursor was a pointer to a dataset > already resident on the database, and were used to return a reference to = a > dataset resident in the database to a client application. > > What I am trying to do is build a table valued variable in a client > application then submit it to a stored procedure resident on the database= , > and have that stored procedure manipulate it as though it were a table [b= e > it inserting, updating or deleting based upon its contents]. > > Is this possible? > > I apologise for not making my question more clear. Is the following too simplistic (maybe I have not understood your question either, but it seems that postgresql makes it so simple, that "problems" you had to solve in ORACLKE, aren't a "problem" in postgresql.) create type ty_app_user as ( aur_id integer, ... etc ); create or replace function prAddUsers ( p_in_users tty_app_user ) returns void as $$ declare begin insert into users (aur_id ... etc ) values (p_in_users.aur_id, etc...); end; $$ language plpgsql; > Thanks, > > Andrew. > >> Date: Fri, 23 Oct 2009 20:10:48 +0200 >> Subject: Re: [SQL] Table Valued Parameters >> From: pavel.stehule@gmail.com >> To: andrewah@hotmail.com >> CC: pgsql-sql@postgresql.org >> >> 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 >> > user >> > in my application. >> > -- I know that this can be done using PostgreSQL. >> > -- >> > >> > CREATE TYPE TY_APP_USER AS OBJECT >> > ( >> > =A0 aur_id=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 INT >> > , aur_username=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 VARCHAR2(30=A0 CHAR) >> > , aur_is_account_enabled VARCHAR2(1=A0=A0 CHAR) >> > , aur_created_date=A0=A0=A0=A0=A0=A0 DATE >> > , aur_updated_date=A0=A0=A0=A0=A0=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 >> > data >> > type can be >> > -- created and populated by the client application [a java based one i= n >> > my >> > 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 >> > ( >> > =A0 p_in_users IN tty_app_user >> > ) >> > IS >> > BEGIN >> > >> > =A0 INSERT >> > =A0=A0=A0 INTO >> > =A0=A0=A0=A0=A0=A0=A0=A0 users >> > =A0=A0=A0=A0=A0=A0 ( >> > =A0=A0=A0=A0=A0=A0=A0=A0 aur_id >> > =A0=A0=A0=A0=A0=A0 , aur_username >> > =A0=A0=A0=A0=A0=A0 , aur_is_account_enabled >> > =A0=A0=A0=A0=A0=A0 , aur_created_by >> > =A0=A0=A0=A0=A0=A0 , aur_created_date >> > =A0=A0=A0=A0=A0=A0 ) >> > =A0 SELECT >> > =A0=A0=A0=A0=A0=A0=A0=A0 aur_id >> > =A0=A0=A0=A0=A0=A0 , aur_username >> > =A0=A0=A0=A0=A0=A0 , aur_is_account_enabled >> > =A0=A0=A0=A0=A0=A0 , aur_created_by >> > =A0=A0=A0=A0=A0=A0 , aur_created_date >> > =A0=A0=A0 FROM >> > =A0=A0=A0=A0=A0=A0=A0=A0 TABLE >> > =A0=A0=A0=A0=A0=A0=A0=A0 ( >> > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 CAST >> > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ( >> > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 p_in_users AS tty_app_user >> > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ) >> > =A0=A0=A0=A0=A0=A0=A0=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 passi= ng >> > 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 jus= t >> > intended to demonstrate the principle!], and I would be grateful if >> > anybody >> > could help me to arrive at an optimal solution. >> > >> > Cheers, >> > >> > Andrew. >> > >> > >> > >> > >> > >> > >> > ________________________________ >> > Download Messenger onto your mobile for free. Learn more. >> >> -- >> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-sql > > ________________________________ > Chat to your friends for free on selected mobiles. Learn more. > ________________________________ > Chat to your friends for free on selected mobiles. Learn more. --=20 Brian Modra Land line: +27 23 5411 462 Mobile: +27 79 69 77 082 5 Jan Louw Str, Prince Albert, 6930 Postal: P.O. Box 2, Prince Albert 6930 South Africa http://www.zwartberg.com/