Re: Update a composite nested type variable
От | Luca Vernini |
---|---|
Тема | Re: Update a composite nested type variable |
Дата | |
Msg-id | CAHZ=uVCk7o_UgLkFRvNKvGUEK2VGQ=NWKrrmr0zwVsWzELE6ew@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Update a composite nested type variable (David Johnston <polobo@yahoo.com>) |
Ответы |
Re: Update a composite nested type variable
|
Список | pgsql-sql |
2013/7/8 David Johnston <polobo@yahoo.com>
All right. Here you are a complete example. Just tested it.
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;
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 по дате отправления: