Dynamic column names in plpgsql - Mailing list pgsql-novice

From Derrick Betts
Subject Dynamic column names in plpgsql
Date
Msg-id 01a601c6261b$0a4e6480$0202a8c0@main
Whole thread Raw
Responses Re: Dynamic column names in plpgsql  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
I'm trying to write a function that uses dynamic column names to fetch the results within those columns.  I have written the following, however, the result is the name of the column, not the value within the column.  I've tried several ideas and searched all over looking for a solution.  Does anyone know if there is one?  I have looked into the
PQfnumber(const PGresult *res, const char *column_name); along with PQgetvalue(const PGresult *res, int row_number, int column_number); which would likely work, but I think it is designed for C code, not plpgsql.  I'm using version 8.0.1 on Redhat.
 
FOR rec IN SELECT column_name FROM information_schema.columns WHERE table_name = 'contact_app_gfe'  AND column_name like '%total'  ORDER BY column_name
LOOP
    holder = ''; 
    SELECT rec.column_name INTO holder FROM contact_app_gfe WHERE contactid = 2057;
    IF holder <> '' THEN
        RAISE NOTICE 'Value: %', holder ; --this is giving me the column names
    END IF;
END LOOP;
RETURN;
 
Thanks, Derrick
 

pgsql-novice by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Insert Text
Next
From: Bruno Wolff III
Date:
Subject: Re: Upgrade to PG 8 before starting major development?