Hi all, I'd like to write a function that would allow me to verify some attributes on a table so that I could give a meaningful error message...
I've been playing with passing in to a plpgsql function the following things.
CREATE OR REPLACE FUNCTION fn_verifyObject( VARCHAR, VARCHAR, BIGINT, VARCHAR ) RETURNS BOOLEAN AS' declare tableName ALIAS FOR $1; idColumn ALIAS FOR $2; objectId ALIAS FOR $3; errorMsg ALIAS FOR $4;
recCheckObject RECORD; constructedSql TEXT := ''''; begin constructedSql = ''SELECT INTO recCheckObject * FROM '' || tableName || '' WHERE '' || idColumn || '' = '' || objectId; EXECUTE constructedSql;
-- this is where I expect the command to run, as though I had typed it in and thus populate, or fail to populate the record recCheckObject. IF NOT FOUND THEN RAISE EXCEPTION ''VERIFY OBJECT FAILED FOR:%:%:%:%'', tableName, idColumn, objectId, errorMsg; END IF;