pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: J. Greg Davidson <jgd@well.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: jgd@well.com
Subject: 8.4beta[12]  set returning function fails -- was O.K. with 8.3
Date: Wed, 10 Jun 2009 16:58:43 -0700 (PDT)
Message-ID: <45800.74.7.85.158.1244678323.squirrel@webmail.well.com> (raw)

Dear PostgreSQL Hackers,

Through PostgreSQL 8.3, both of the following functions worked, using
  generate_series(array_lower($1, 1), array_upper($1, 1)) i
instead of generate_subscripts($1, 1).

With PostgreSQL 8.4, both are accepted, but only the second one works,
regardless of whether I use generate_subscripts or the old way.  The error
is shown.  What's going on?

Thanks,

_Greg

CREATE OR REPLACE
FUNCTION array_to_set(ANYARRAY) RETURNS SETOF RECORD AS $$
  SELECT i AS "index", $1[i] AS "value" FROM generate_subscripts($1, 1) i
$$ LANGUAGE SQL STRICT IMMUTABLE;
COMMENT ON FUNCTION array_to_set(ANYARRAY) IS
'returns the array as a set of RECORD(index, value) pairs';

SELECT array_to_set(ARRAY['one', 'two']);

-- BREAKS IN PG 8.4 beta1 & beta2, vis:
--
--	ERROR:  0A000: set-valued function called in context that cannot accept
a set
--	CONTEXT:  SQL function "array_to_set" during startup
--	LOCATION:  fmgr_sql, functions.c:644

CREATE OR REPLACE
FUNCTION array_to_list(ANYARRAY) RETURNS SETOF ANYELEMENT AS $$
    SELECT $1[i] FROM generate_subscripts($1, 1) i
$$ LANGUAGE SQL STRICT IMMUTABLE;
COMMENT ON FUNCTION array_to_list(ANYARRAY) IS
'returns the array as a set of its elements from lowest to highest;
- can we guarantee the values will be seen in order???';

SELECT array_to_list(ARRAY['one', 'two']);

-- Works great, vis:
--
--	  array_to_list
--	---------------
--	 one
--	 two
--	(2 rows)




view thread (3+ messages)  latest in thread

Message-ID: <45800.74.7.85.158.1244678323.squirrel@webmail.well.com>
Permalink:  ../45800.74.7.85.158.1244678323.squirrel@webmail.well.com/
Also on:    postgresql.org/message-id/45800.74.7.85.158.1244678323.squirrel@webmail.well.com

 · 

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-hackers@postgresql.org
  Cc: jgd@well.com
  Subject: Re: 8.4beta[12]  set returning function fails -- was O.K. with 8.3
  In-Reply-To: <45800.74.7.85.158.1244678323.squirrel@webmail.well.com>

* 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