By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

adressing column

P: n/a
i have the following function:

declare
prim_col_name Alias for $1;
prim_col_val Alias for $2;
my_column Alias for $3;
link_table Alias for $4;
link_col Alias for $5;
data_table alias for $6;
my_record Record;
result_string varchar;
i integer;
begin
result_string := '';
i := 0;
For my_record in execute 'select ' || my_column || ' from ' ||
data_table || ' where ' || link_col || ' in (select ' || link_col || '
from ' || link_table || ' where ' || prim_col_name || ' = ' ||
prim_col_val || ') order by lower(' || my_column || ')' loop
if i = 0 then
result_string := my_record.col;
else
result_string := result_string || ', ' || my_record.col;
end if;
i := i + 1;
end loop;
return result_string;
end
now i am searching for a way, to access my_column in my_record (now it
just works if my_column = 'col')
can anyone help please!
thanx
steffn
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wednesday 01 October 2003 11:20, Stefan Leitich wrote:
i have the following function: [snip code]
now i am searching for a way, to access my_column in my_record (now it
just works if my_column = 'col')
can anyone help please!


That's not going to work in plpgsql at the moment. Because it's "compiled", it
has problems with things like this.

The usual answer is to use pltcl or some other more dynamic language.

In you particular example you could just build your execute statement as:
... || my_column || ' AS foo FROM ' || ...

Then you can access the column as "foo"
--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #2

P: n/a
thanx a lot.
i thought much to complicated!
this will work in my case perfectly!

Richard Huxton wrote:
On Wednesday 01 October 2003 11:20, Stefan Leitich wrote:

i have the following function:

[snip code]

now i am searching for a way, to access my_column in my_record (now it
just works if my_column = 'col')
can anyone help please!


That's not going to work in plpgsql at the moment. Because it's "compiled", it
has problems with things like this.

The usual answer is to use pltcl or some other more dynamic language.

In you particular example you could just build your execute statement as:
... || my_column || ' AS foo FROM ' || ...

Then you can access the column as "foo"

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.