pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedAssigning values to array components.
2+ messages / 2 participants
[nested] [flat]
* Assigning values to array components.
@ 2003-09-11 20:01 Rich Cullingford <rculling@sysd.com>
0 siblings, 1 reply; 2+ messages in thread
From: Rich Cullingford @ 2003-09-11 20:01 UTC (permalink / raw)
To: pgsql-interfaces
Hello All,
I have a small application (based on sorting inet[] arrays) that
requires building an array of bigints, one for each inet in the array.
This is doable in most programming languages with a notation like:
inet_bigints[i] := inet2bigint(ip)
Unfortunately, plpgsql doesn't seem to allow that kind of assignment, as
loading the following into psql reveals:
create or replace function foobaz()
RETURNS bigint[]
AS '
DECLARE
answer bigint[];
BEGIN
answer[1] := 12345;
RETURN answer;
END;
'
LANGUAGE 'plpgsql';
When I try to run this:
select foobaz();
WARNING: plpgsql: ERROR during compile of foobaz near line 4
ERROR: parse error at or near "["
The system also won't let me initialize the array in the DECLARE
section. I've looked through the archives for the past few years for
hints about this, but haven't found anything. Is there a plpgsql
reference that's more 'complete' than the one that comes with the PG
distribution?
Any help greatly appreciated.
Rich Cullingford
rculling@sysd.com
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Assigning values to array components.
@ 2003-09-11 21:08 Tom Lane <tgl@sss.pgh.pa.us>
parent: Rich Cullingford <rculling@sysd.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2003-09-11 21:08 UTC (permalink / raw)
To: Rich Cullingford <rculling@sysd.com>; +Cc: pgsql-interfaces
Rich Cullingford <rculling@sysd.com> writes:
> create or replace function foobaz()
> RETURNS bigint[]
> AS '
> DECLARE
> answer bigint[];
> BEGIN
> answer[1] := 12345;
> RETURN answer;
> END;
> '
> LANGUAGE 'plpgsql';
> select foobaz();
> WARNING: plpgsql: ERROR during compile of foobaz near line 4
> ERROR: parse error at or near "["
IIRC, Joe Conway fixed that for 7.4. I can get your example to work
in CVS tip if I modify the DECLARE to
answer bigint[] = ''{}'';
Without that, you're trying to combine a NULL array with a nonnull
entry, which is going to give a NULL result.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-09-11 21:08 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-11 20:01 Assigning values to array components. Rich Cullingford <rculling@sysd.com>
2003-09-11 21:08 ` Tom Lane <tgl@sss.pgh.pa.us>
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