Re: Update a composite nested type variable

From: Luca Vernini <lucazeo(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Update a composite nested type variable
Date: 2013-07-08 19:44:22
Message-ID: CAHZ=uVCk7o_UgLkFRvNKvGUEK2VGQ=NWKrrmr0zwVsWzELE6ew@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

2013/7/8 David Johnston <polobo(at)yahoo(dot)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;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David Johnston 2013-07-08 23:25:12 Re: Update a composite nested type variable
Previous Message David Johnston 2013-07-08 19:01:25 Re: Update a composite nested type variable