pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Muhammad Altaf <mmalik_altaf@yahoo.com>
To: dave.cramer@credativ.ca <dave.cramer@credativ.ca>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Struct Support
Date: Sat, 20 Oct 2012 20:44:02 -0700 (PDT)
Message-ID: <1350791042.11899.YahooMailNeo@web161806.mail.bf1.yahoo.com> (raw)

Hi Dave,
 I am in process of implementing java.sql.Struct to support composite types as OUT/IN parameters in postgres JDBC Driver. I am almost done with that, but while writing test cases, I came across an issue with return values. The Struct parameters are successfully being passed and returned as OUT parameters (I have tested that with multiple out and in parameters of type Struct as well). But when it comes to returning a struct value, server returns two fields in RowDescription which makes driver believe that these are actually two parameters. Initially I thought I am doing something wrong at the Driver level, but pgAdminIII showed the same behavior. I'll show both behaviors in pgAdminIII.

SQL Script:
create type city as (city_id int4, city_name text);
create type address as (street_address text, city city);
create or replace function udt_f1(a in varchar, b out city, c out address) returns RECORD AS $$
 DECLARE 
    c_city city;
    BEGIN 
    select 1,a into b;
    select 2, 'City Name' into c_city; 
    select 'Street address',c_city into c;
    END;$$ language 'plpgsql';
    
create or replace function udt_f2(a in int4, b in city) returns city AS $$ 
declare 
    c_city city; 
BEGIN 
    select a,b.city_name into c_city; 
    return c_city; 
END;$$ language 'plpgsql';


 Now, in pgAdmin, call udt_f1
    select * from udt_f1('Test City');
This will display two columns with appropriate city and address details.

Now call udt_f2
    select * from udt_f2(100, '(4, "Washington")');
Instead of displaying a single city column, it displays two columns. The first as integer (city_id) and the second being text (city_name).

Can you please confirm I am not correct and something needs to be done while calling this function to get it working?


Thanks,
Altaf Malik


view thread (3+ messages)  latest in thread

Message-ID: <1350791042.11899.YahooMailNeo@web161806.mail.bf1.yahoo.com>
Permalink:  ../1350791042.11899.YahooMailNeo@web161806.mail.bf1.yahoo.com/
Also on:    postgresql.org/message-id/1350791042.11899.YahooMailNeo@web161806.mail.bf1.yahoo.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: mmalik_altaf@yahoo.com, dave.cramer@credativ.ca
  Subject: Re: Struct Support
  In-Reply-To: <1350791042.11899.YahooMailNeo@web161806.mail.bf1.yahoo.com>
  References: <1350791042.11899.YahooMailNeo@web161806.mail.bf1.yahoo.com>

* 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