[postgis-users] pl/pgsql question: dynamic access to record.column

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Wed Jan 10 14:50:52 PST 2007


Hi Dylan,


On Wed, 2007-01-10 at 14:04 -0800, Dylan Beaudette wrote:

(cut)

I think the easiest way to do this is use an alias, so that your chosen
column is always returned as "the_column" in your hz_record variable,
e.g.

		FOR hz_record in 
			EXECUTE 'select top, bottom, ' 
			|| quote_ident(the_column)
			|| ' AS the_column from horizon '
			|| ' where pedon_id = '
			|| quote_literal(the_pedon_id) 
			|| ' and ( bottom >= '
			|| top_lim 
			|| ' and top <= '
			|| bottom_lim
			|| ' ) '
			|| ' and '
			|| quote_ident(the_column)
			|| ' is not null'
			|| ' order by top '
			LOOP 

This should then allow you to use your original version at the end of
the loop, e.g.
			
--			the weighted-avg clay percent and frags within the PCS
			wt_column := wt_column + (hz_record.the_column * thick) ;


HTH,

Mark.





More information about the postgis-users mailing list