pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to iterate through arrays?
4+ messages / 3 participants
[nested] [flat]

* How to iterate through arrays?
@ 2005-02-09 13:59 NosyMan <nosyman@gmail.com>
  2005-02-09 14:16 ` Re: How to iterate through arrays? PFC <lists@boutiquenumerique.com>
  0 siblings, 1 reply; 4+ messages in thread

From: NosyMan @ 2005-02-09 13:59 UTC (permalink / raw)
  To: pgsql-sql

Hi there,

I'm trying to iterate through arrays in PL/PGSQL:
....
	DECLARE
		update_query CHAR;
		update_query_params CHAR ARRAY[6];
	BEGIN
			update_query_params[1]:='some text';		
			
			RAISE NOTICE 'Testing element %', update_query_params[1];
	END
.....


It does not 'compile'... :-(. Can you tell me what is the problem?

Thanks,
Nosy



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to iterate through arrays?
  2005-02-09 13:59 How to iterate through arrays? NosyMan <nosyman@gmail.com>
@ 2005-02-09 14:16 ` PFC <lists@boutiquenumerique.com>
  2005-02-09 14:26   ` Re: How to iterate through arrays? NosyMan <nosyman@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: PFC @ 2005-02-09 14:16 UTC (permalink / raw)
  To: NosyMan <nosyman@gmail.com>; pgsql-sql


- use TEXT instead of CHAR (what is CHAR without (n) ?)
- inintialize your array with '{}' because it is created as NULL if you  
just declare it without setting it to an empty array.

> Hi there,
>
> I'm trying to iterate through arrays in PL/PGSQL:
> ....
> 	DECLARE
> 		update_query CHAR;
> 		update_query_params CHAR ARRAY[6];
> 	BEGIN
> 			update_query_params[1]:='some text';		
> 			
> 			RAISE NOTICE 'Testing element %', update_query_params[1];
> 	END
> .....
>
>
> It does not 'compile'... :-(. Can you tell me what is the problem?
>
> Thanks,
> Nosy
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to iterate through arrays?
  2005-02-09 13:59 How to iterate through arrays? NosyMan <nosyman@gmail.com>
  2005-02-09 14:16 ` Re: How to iterate through arrays? PFC <lists@boutiquenumerique.com>
@ 2005-02-09 14:26   ` NosyMan <nosyman@gmail.com>
  2005-02-09 15:06     ` Re: How to iterate through arrays? John DeSoi <desoi@pgedit.com>
  0 siblings, 1 reply; 4+ messages in thread

From: NosyMan @ 2005-02-09 14:26 UTC (permalink / raw)
  To: pgsql-sql

I think the problem is not there. I got the following error:
'ERROR:  syntax error at or near "[" at character 1234', the line is: RAISE 
NOTICE '% ...',update_query_params[1];

May be someone give a code sample...

Thanks




Pe data de Mie 09 Feb 2005 16:16, ati scris:
> - use TEXT instead of CHAR (what is CHAR without (n) ?)
> - inintialize your array with '{}' because it is created as NULL if you  
> just declare it without setting it to an empty array.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to iterate through arrays?
  2005-02-09 13:59 How to iterate through arrays? NosyMan <nosyman@gmail.com>
  2005-02-09 14:16 ` Re: How to iterate through arrays? PFC <lists@boutiquenumerique.com>
  2005-02-09 14:26   ` Re: How to iterate through arrays? NosyMan <nosyman@gmail.com>
@ 2005-02-09 15:06     ` John DeSoi <desoi@pgedit.com>
  0 siblings, 0 replies; 4+ messages in thread

From: John DeSoi @ 2005-02-09 15:06 UTC (permalink / raw)
  To: NosyMan <nosyman@gmail.com>; +Cc: pgsql-sql


On Feb 9, 2005, at 9:26 AM, NosyMan wrote:

> I think the problem is not there. I got the following error:
> 'ERROR:  syntax error at or near "[" at character 1234', the line is: 
> RAISE
> NOTICE '% ...',update_query_params[1];

The problem here is RAISE, NOTICE, etc. can only use simple variables 
in the format string. Try it like:

myTextVar := update_query_params[1];
NOTICE '% ...',myTextVar;


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-02-09 15:06 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-09 13:59 How to iterate through arrays? NosyMan <nosyman@gmail.com>
2005-02-09 14:16 ` PFC <lists@boutiquenumerique.com>
2005-02-09 14:26   ` NosyMan <nosyman@gmail.com>
2005-02-09 15:06     ` John DeSoi <desoi@pgedit.com>

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