Error: type of parameter does not match that when preparing the plan postgresql-9.3.3

Error: type of parameter does not match that when preparing the plan postgresql-9.3.3

我在unix上使用postgresql-9.3.3做作业,我的代码如下:


create type MatchingRecord as ("table" text, "column" text, nexamples integer);

create or replace function Q2("table" text, pattern text) returns setof MatchingRecord
as $$
declare
    record_q2 MatchingRecord;
    curs1_q2 record;
    curs2_q2 record;
    n integer;
    value text;
begin
    for curs1_q2 in select column_name from information_schema.columns where table_name =  
    loop
        n := 0;
        raise notice 'curs1 = %', quote_ident(curs1_q2.column_name);
        for curs2_q2 in execute 'select '||quote_ident(curs1_q2.column_name)||' as col from '||quote_ident() 
        loop
            value := (curs2_q2.col::text); 
            if(value ~ ) then n := n + 1;
            end if;
        end loop;
        if (n > 0) then record_q2.table := ; record_q2.column := curs1_q2.column_name; record_q2.nexamples := n;
        return next record_q2;
        end if;
    end loop;
    return;
end;
$$ language plpgsql;

有两个循环,在第一个循环中我需要从系统 table information_schema.columns 中获取列名,然后我想在第二个循环中使用select,列名是第一个循环curs2_q2.column_name的内容,table是输入参数</code>。当我执行上面的代码时,错误显示为:</p> <hr> <pre><code>proj2=# select * from q2('subjects', 'COMP\d\d\d'); NOTICE: curs1 = id NOTICE: curs1 = code ERROR: type of parameter 14 (character) does not match that when preparing the plan (integer) CONTEXT: PL/pgSQL function q2(text,text) line 16 at assignment


如何解决 'plan caching' 问题?

检查这个。对我有用。

create or replace function Q2("table" text, pattern text) returns setof MatchingRecord
as $$
declare
    record_q2 MatchingRecord;
    curs1_q2 record;
    curs2_q2 record;
    n integer;
begin
    for curs1_q2 in select column_name from information_schema.columns where table_name =  
    loop
        n := 0;
        raise notice 'curs1 = %', quote_ident(curs1_q2.column_name);
        for curs2_q2 in execute 'select '||quote_ident(curs1_q2.column_name)||'::text as col from '||quote_ident() 
        loop
            if(curs2_q2.col ~ )   then n := n + 1;
            end if;
        end loop;
        if (n > 0) then record_q2.table := ; record_q2.column := curs1_q2.column_name; record_q2.nexamples := n;
        return next record_q2;
        end if;
    end loop;
    return;
end;
$$ language plpgsql;