CREATE OR REPLACE FUNCTION test123(column_name VARCHAR(40)) RETURNS RECORD AS $$
DECLARE
rec RECORD ;
BEGIN
SELECT * INTO rec FROM my_table WHERE column_name=1 LIMIT 1;
RETURN rec;
END;
$$ LANGUAGE plpgsql;
你如何将列名称传递给函数,并在查询中使用该名称?
上面的代码无法正常工作:
error: operator does not exist: character varying = integer