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