Loop in function does not work as expected
问题 Using PostgreSQL 9.0.4 Below is a very similar structure of my table: CREATE TABLE departamento ( id bigserial NOT NULL, master_fk bigint, nome character varying(100) NOT NULL CONSTRAINT departamento_pkey PRIMARY KEY (id), CONSTRAINT departamento_master_fk_fkey FOREIGN KEY (master_fk) REFERENCES departamento (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) And the function I created: CREATE OR REPLACE FUNCTION fn_retornar_dptos_ate_raiz(bigint[]) RETURNS bigint[] AS $BODY$ DECLARE