Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Using PostgreSQL, column values from a table for 1st record are stored in a record variable. for example: let the variable be:

recordvar

and different columns be:

name,id,gender,age
recordvar.name

But I want to retrieve that colum value like

var =name

then

recordvar.var

How can I do this? I don't want to use hstore.

Here is the sample code

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 is not working

share|improve this question
    
What language are you coding in? – Gary May 24 at 12:05
    
postgresql.........doing this in procedure function – Tauseef Rehan May 24 at 12:24
    
Maybe you can use FETCH _cursorname INTO _recordvar; Then you can use _recordvar.name for example. – v.chjen May 24 at 12:51
    
Hope Sample code will help in understanding problem – Tauseef Rehan May 24 at 12:57
    
How many columns do you have in one record? – Abdul May 24 at 13:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.