I have a function where I want to be able to use a text variable as a field name in a Postgres function.
DECLARE
_currentEmployee text;
_myCount integer;
BEGIN
FOR _record IN
SELECT ...
LOOP
_currentEmployee = _record.name
_myCount = (SELECT count(*) FROM tblTraining
WHERE tblTraining._currentEmployee = 4);
If _mycount = 0 ...
END LOOP;
Basically it's a routine to check the training record of each employee. The table schema has obvious issues because the employees are all entered as columns in the training table instead of normalized id's in each row, but I have to work with what I've got here.
Whenever I run the function, it treats the _currentEmployee
literally instead of replacing it with the field name and processing correctly. I get the error:
_currentlEmployee is not a field of tblTraining
Suggestions?