Re: Update a composite nested type variable - Mailing list pgsql-sql

From Luca Vernini
Subject Re: Update a composite nested type variable
Date
Msg-id CAHZ=uVCk7o_UgLkFRvNKvGUEK2VGQ=NWKrrmr0zwVsWzELE6ew@mail.gmail.com
Whole thread Raw
In response to Re: Update a composite nested type variable  (David Johnston <polobo@yahoo.com>)
Responses Re: Update a composite nested type variable
List pgsql-sql
2013/7/8 David Johnston <polobo@yahoo.com>

This may be a pl/pgsql limitation but you should probably provide a complete
self-contained example with your attempt so that user-error can be
eliminated.

David J.


All right. Here you are a complete example. Just tested it.
Sorry for the long email.

 CREATE TYPE type_customer AS
   (id integer,
    cust_name character varying(100),
    email character varying(100));

CREATE TYPE type_supercustomer AS
   (cus_data type_customer,
    superpower character varying);

CREATE TABLE public.table_customer
(
   id serial NOT NULL,
   cust_name character varying(100) NOT NULL,
   email character varying(100) NOT NULL,
   PRIMARY KEY (id)
)
WITH (OIDS = FALSE);

CREATE TABLE public.table_supercustomer
(
   superpower character varying(100) NOT NULL
)
INHERITS (table_customer)
WITH (OIDS = FALSE);
ALTER TABLE table_supercustomer ADD PRIMARY KEY (id);

CREATE OR REPLACE FUNCTION function_read_supercustomer()
  RETURNS SETOF type_supercustomer AS
$BODY$
DECLARE
    retset        type_supercustomer;
BEGIN
    FOR retset IN
        SELECT (id, cust_name, email), superpower
        FROM table_supercustomer
    LOOP
        retset.superpower := initcap(retset.superpower);--works
        (retset.cus_data).email = 'anything you want';--does not work
        RETURN NEXT retset;
    END LOOP;
END;
$BODY$
  LANGUAGE plpgsql STABLE STRICT COST 100 ROWS 1000;

pgsql-sql by date:

Previous
From: David Johnston
Date:
Subject: Re: Update a composite nested type variable
Next
From: David Johnston
Date:
Subject: Re: Update a composite nested type variable