Re: [GENERAL] Dynamically access to field on a RECORD variable

2005-05-03 Thread Ricardo Vaz Mannrich
If it's not possible, can I create a function that gets a RECORD and a tablename and returns the correct value. For example: CREATE FUNCTION my_value(TEXT, RECORD) RETURNS TEXT AS ' DECLARE table_name ALIAS FOR $1 rec ALIAS FOR $2 BEGIN IF (table_name = 'my_table1') THEN RETU

Re: [GENERAL] Dynamically access to field on a RECORD variable

2005-05-03 Thread hatuan
I am newbie. Could you give a example? Thank you. > Ricardo Vaz Mannrich <[EMAIL PROTECTED]> writes: > > Is it possible? > > Not in plpgsql. I believe you could do it in any of the other PLs though. > > regards, tom lane > > ---(end of broadcast)---

Re: [GENERAL] Dynamically access to field on a RECORD variable

2005-05-03 Thread Tom Lane
Ricardo Vaz Mannrich <[EMAIL PROTECTED]> writes: > Is it possible? Not in plpgsql. I believe you could do it in any of the other PLs though. regards, tom lane ---(end of broadcast)--- TIP 9: the planner will ignore your des

Re: [GENERAL] Dynamically access to field on a RECORD variable

2005-05-03 Thread Pavel Stehule
Hello, It's not possible. Not in plpgsql. Its possible in plperl or plpython or pltcl. But you can do CREATE OR REPLACE FUNCTION my_fce(text) returns text AS $$ DECLARE _r RECORD; BEGIN FOR _r IN EXECUTE 'SELECT '||$1||' AS _c FROM my_table ...' LOOP RETURN _r._c; END LOOP; END; $$ LANG

[GENERAL] Dynamically access to field on a RECORD variable

2005-05-03 Thread Ricardo Vaz Mannrich
Supose I have this function CREATE OR REPLACE my_func(TEXT) RETURNS text AS ' DECLARE var_name ALIAS FOR $1; rec RECORD; BEGIN SELECT * INTO rec FROM my_table WHERE my_key = 1; -- Here is my problem RETURN rec.var_name; END; ' LANGUAGE plpgsql; SELECT my_func('my_field')