one last patch - array lower and upper bound

From: Joe Conway <mail(at)joeconway(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: one last patch - array lower and upper bound
Date: 2002-09-02 07:17:39
Message-ID: 3D731093.5020709@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

The "Allow easy display of usernames in a group (pg_hba.conf uses groups
now)" item on the open items, and subsequent plpgsql function I sent in,
made me realize it was too hard to get the upper and lower bound of an
array. The attached creates two functions that I think will be very
useful when combined with the ability of plpgsql to return sets.

array_lower(array, dim_num)
- and -
array_upper(array, dim_num)

They return the value (as an int) of the upper and lower bound of the
requested dim in the provided array.

With these, the show_group() function from before looks like:

CREATE OR REPLACE FUNCTION show_group(text) RETURNS SETOF text AS '
DECLARE
loginname text;
low int;
high int;
BEGIN
SELECT INTO low array_lower(grolist,1)
FROM pg_group WHERE groname = $1;
SELECT INTO high array_upper(grolist,1)
FROM pg_group WHERE groname = $1;

FOR i IN low..high LOOP
SELECT INTO loginname s.usename
FROM pg_shadow s join pg_group g on s.usesysid = g.grolist[i];
RETURN NEXT loginname;
END LOOP;
RETURN;
END;
' LANGUAGE 'plpgsql';

If possible, and no objections, please apply for 7.3.

catversion.h bump and initdb required.

Thanks,

Joe

Attachment Content-Type Size
array-util.1.patch text/plain 3.9 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Serguei Mokhov 2002-09-02 08:11:17 Re: fix for palloc() of user-supplied length
Previous Message Bruce Momjian 2002-09-02 06:26:53 Re: fulltextindex update