Connecting Tech Pros Worldwide Forums | Help | Site Map

Assigning Values to Arrays

Zitan Broth
Guest
 
Posts: n/a
#1: Nov 12 '05
Greetings All,

Running pg 7.3.4 and was reading: http://archives.postgresql.org/pgsql...9/msg00018.php . Basically want to assign values to an array and then a 2d array.

However I can't get this to run in properly I get a syntax error (at or near "[") with function listed below.

Any suggestions are greatly appreciated :-)

Thanks,
Z.

btw, is there an user-contributed notes section of the pg documentation I could post a working example too (yeah php developer in the house :-)).

Test procedure::

create table test_output(
output_num_arr numeric[][],
output_txt_arr TEXT[],
output_str text
);

CREATE OR REPLACE FUNCTION F_TEST(TEXT) RETURNS NUMERIC AS '
DECLARE
HeaderArray text[] = ''{}'';
BEGIN
HeaderArray[1] := \'hi\';
HeaderArray[2] := \'this\';
HeaderArray[3] := \'is\';
HeaderArray[4] := \'not\';
HeaderArray[5] := \'a\';
HeaderArray[6] := \'test\';

insert into test_output(output_txt_arr) values (HeaderArray);
insert into test_output(output_str) values (HeaderArray[1]);
insert into test_output(output_str) values (HeaderArray[2]);
insert into test_output(output_str) values (HeaderArray[3]);
insert into test_output(output_str) values (HeaderArray[4]);
insert into test_output(output_str) values (HeaderArray[5]);
insert into test_output(output_str) values (HeaderArray[6]);

END;
'LANGUAGE 'plpgsql';

select F_TEST('a');
select * from test_output;
drop function F_TEST(TEXT);
drop table test_output;




Oliver Elphick
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Assigning Values to Arrays


On Wed, 2003-10-08 at 11:41, Zitan Broth wrote:[color=blue]
> Greetings All,
>
> Running pg 7.3.4 and was reading:
> http://archives.postgresql.org/pgsql...9/msg00018.php . Basically want to assign values to an array and then a 2d array.
>
> However I can't get this to run in properly I get a syntax error (at
> or near "[") with function listed below.
>
> Any suggestions are greatly appreciated :-)
>[/color]

Your function does not have a return statement.

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Let no man say when he is tempted, I am tempted of
God; for God cannot be tempted with evil, neither
tempteth he any man; But every man is tempted, when he
is drawn away of his own lust, and enticed."
James 1:13,14


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Zitan Broth
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Assigning Values to Arrays


But that isn't causing the syntax error .....

From rereading the Post I am certain that I need 7.4 rather than 7.3.4 for
this to work :-)

Thanks for the response.

Z.

[color=blue]
> On Wed, 2003-10-08 at 11:41, Zitan Broth wrote:[color=green]
> > Greetings All,
> >
> > Running pg 7.3.4 and was reading:
> > http://archives.postgresql.org/pgsql...9/msg00018.php .[/color][/color]
Basically want to assign values to an array and then a 2d array.[color=blue][color=green]
> >
> > However I can't get this to run in properly I get a syntax error (at
> > or near "[") with function listed below.
> >
> > Any suggestions are greatly appreciated :-)
> >[/color]
>
> Your function does not have a return statement.
>[/color]



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Closed Thread