X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4E05BDAE73 for ; Wed, 26 Oct 2005 09:38:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79507-05 for ; Wed, 26 Oct 2005 12:38:38 +0000 (GMT) Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by svr1.postgresql.org (Postfix) with ESMTP id 0AE2BDAE01 for ; Wed, 26 Oct 2005 09:38:39 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id CE85017A36 for ; Wed, 26 Oct 2005 14:38:41 +0200 (CEST) Received: from pjetlic.mobart.hr ([127.0.0.1]) by localhost (pjetlic [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 15174-03 for ; Wed, 26 Oct 2005 14:38:41 +0200 (CEST) Received: from mike.mobart.hr (mike.mobart.hr [192.168.10.94]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by pjetlic.mobart.hr (Postfix) with ESMTP id A47D517A13 for ; Wed, 26 Oct 2005 14:38:41 +0200 (CEST) Subject: RETURNS SETOF primitive returns results in parentheses From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Organization: Mob-Art Date: Wed, 26 Oct 2005 14:38:42 +0200 Message-Id: <1130330322.7400.45.camel@ekim> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by OpenSource AV+AS Mail Server X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005] X-Spam-Level: X-Archive-Number: 200510/321 X-Sequence-Number: 23174 Consider this function: CREATE OR REPLACE FUNCTION php_get_subfield_data_repeating(int4, "varchar") RETURNS SETOF "varchar" AS $BODY$ DECLARE aRecordID ALIAS FOR $1; aSubFieldId ALIAS FOR $2; returnValue record; subFieldNumber char(3); subFieldLetter char(1); BEGIN subFieldNumber = substr(aSubFieldId, 1, 3); subFieldLetter = substr(aSubFieldId, 4); FOR returnValue IN SELECT "subfieldValue"::varchar FROM "records_sub" WHERE "fieldTag" = subFieldNumber AND "subfieldTag" = subFieldLetter AND "recordId" = aRecordId LOOP RETURN NEXT returnValue; END LOOP; RETURN; END $BODY$ LANGUAGE 'plpgsql' VOLATILE; Now, when I do this: biblio3=# select * from php_get_subfield_data_repeating(1,'606a'); php_get_subfield_data_repeating1 ---------------------------------- (Anđeli) (ofsajd) (2 rows) I have return values in parentheses. However, if I create a new type: CREATE TYPE subfield_data_type AS (subfield_data varchar); And then drop the function and recreate it like this: CREATE OR REPLACE FUNCTION php_get_subfield_data_repeating(int4, "varchar") RETURNS SETOF subfield_data_type AS $BODY$ ... And then when I run the function, the results are ok: biblio3=# select * from php_get_subfield_data_repeating(1,'606a'); subfield_data --------------- Anđeli ofsajd (2 rows) Am I doing something wrong here? Why do I need to create type with only one member of type varchar to have results without the parentheses? Mike P.S. The subFieldValue field in the records_sub table is of type varchar(4096). -- Mario Splivalo Mob-Art mario.splivalo@mobart.hr "I can do it quick, I can do it cheap, I can do it well. Pick any two."