使用PostgreSQL,第一条记录的表中的列值存储在记录变量中。例如:让变量为:
recordvar
并且不同的列是:
name,id,gender,age
recordvar.name
但我想检索像
这样的colum值var =name
然后
recordvar.var
我该怎么做?我不想使用hstore。
以下是示例代码
CREATE OR REPLACE FUNCTION public.get_all_rooms()
RETURNS text AS
$BODY$
DECLARE
total integer;
titles TEXT DEFAULT '';
rec_croom RECORD;
rec_delement integer;
rec_locations integer;
rec_dname varchar;
starts_with text = NULL;
ends_with text = NULL;
de_name varchar;
--de_array integer[];
de_arr_val integer;
sql text;
cur_croom CURSOR
FOR SELECT *
FROM public.tmp_all_controlroom_2;
BEGIN
-- Open the cursor
OPEN cur_croom;
LOOP
-- fetch row into the film
FETCH cur_croom INTO rec_croom;
-- exit when no more row to fetch
EXIT WHEN NOT FOUND;
SELECT locationid INTO rec_locations FROM location WHERE locationcode = rec_croom.location_code;
FOR de_arr_val in select deid from dsmtbl WHERE dsid=74
LOOP
select name INTO de_name from tab1 where deid=de_arr_val;
INSERT INTO datavalue (a, b, c, d, e, value)
VALUES(de_arr_val, 1, rec_croom.cday , rec_locations, 3154, rec_room.de_name);
END LOOP;
END LOOP;
-- Close the cursor
CLOSE cur_croom;
RETURN titles;
END; $BODY$
rec_room.de_name无效