pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mario Splivalo <mario.splivalo@mobart.hr>
To: pgsql-sql@postgresql.org
Subject: RETURNS SETOF primitive returns results in parentheses
Date: Wed, 26 Oct 2005 14:38:42 +0200
Message-ID: <1130330322.7400.45.camel@ekim> (raw)

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."






view thread (8+ messages)  latest in thread

Message-ID: <1130330322.7400.45.camel@ekim>
Permalink:  ../1130330322.7400.45.camel@ekim/
Also on:    postgresql.org/message-id/1130330322.7400.45.camel@ekim

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mario.splivalo@mobart.hr
  Subject: Re: RETURNS SETOF primitive returns results in parentheses
  In-Reply-To: <1130330322.7400.45.camel@ekim>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox