1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| CREATE OR REPLACE FUNCTION transform_table_address () RETURNS transform_address_attribut AS /*$BODY$*/'
DECLARE
rec RECORD;
O transform_address_attribut;
BEGIN
FOR rec IN SELECT company_id FROM address GROUP BY company_id
LOOP
o.company_id := rec.company_id;
SELECT INTO o.company_id, o.name1, o.name2, o.street, o.zip, o.zipcity, o.country, o.state, company_id, name1, name2, street, zip, zipcity, country, state FROM address GROUP BY company_id LIMIT 1;
SELECT INTO o.street2, o.zip2, o.zipcity2, o.country2, o.state2 street, zip, zipcity, country, state FROM address WHERE company_id = rec.company_id GROUP BY company_id LIMIT 1;
IF (SELECT company_id FROM address WHERE company_id = rec.company_id IS NOT NULL )
THEN
EXIT;
END IF;
RETURN NEXT O;
END LOOP;
RETURN;
END;
/*$BODY$*/'
LANGUAGE 'plpgsql'; |
Partager