CREATE OR REPLACE FUNCTION call_rsvp_sip() RETURNS call_rsvp_sip AS ' DECLARE pbx_t ast_pbx%ROWTYPE; user_t ast_user%ROWTYPE; BEGIN SELECT INTO pbx_t pbx_max_trunks, curr_calls FROM ast_pbx WHERE lower(name)="lmadsen"; SELECT INTO user_t sip_maxoutbound, sip_out_calls FROM ast_user WHERE lower(user_name)="lmadsen" AND lower(pbx)="telcel"; RETURN pbx_t.pbx_max_trunks || pbx_t.curr_calls || user_t.sip_maxoutbound || user_t.sip_out_calls; END; ' LANGUAGE PLPGSQL; CREATE TYPE call_rsvp_sip AS (pbx_max varchar(3), pbx_use int4, trunk_max int2, trunk_use int4); Columns definately match up for the column types in the CREATE TYPE