pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedarrays in pl/pgsql
2+ messages / 2 participants
[nested] [flat]
* arrays in pl/pgsql
@ 2003-12-14 09:52 Michael Shapiro <mshapiro@ncsa.uiuc.edu>
2003-12-16 03:55 ` Re: arrays in pl/pgsql Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Michael Shapiro @ 2003-12-14 09:52 UTC (permalink / raw)
To: pgsql-sql
Is it possible in pl/pgsql to declare and then assign to arrays?
For example if I declare an array as follows
DECLARE
dn text[];
How do I assign the first element to a string (say 'a').
I have tried the following (which doesn't work)
dn[1] := \'a\';
The parser doesn't like the [ that follows dn.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: arrays in pl/pgsql
2003-12-14 09:52 arrays in pl/pgsql Michael Shapiro <mshapiro@ncsa.uiuc.edu>
@ 2003-12-16 03:55 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2003-12-16 03:55 UTC (permalink / raw)
To: Michael Shapiro <mshapiro@ncsa.uiuc.edu>; +Cc: pgsql-sql
Michael Shapiro <mshapiro@ncsa.uiuc.edu> writes:
> I have tried the following (which doesn't work)
> dn[1] := \'a\';
> The parser doesn't like the [ that follows dn.
I believe Joe Conway fixed this in 7.4. Note that you also need to
initialize the array to something, because assigning to an element
of a NULL array still yields a NULL array result. For example:
regression=# create or replace function foo() returns text as '
regression'# declare dn text[] := \'{}\';
regression'# begin
regression'# dn[1] := \'a\';
regression'# return dn[1];
regression'# end' language plpgsql;
CREATE FUNCTION
regression=# select foo();
foo
-----
a
(1 row)
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-12-16 03:55 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-12-14 09:52 arrays in pl/pgsql Michael Shapiro <mshapiro@ncsa.uiuc.edu>
2003-12-16 03:55 ` 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