C function taking a relation and returning a similar relation.
От | Ben Martin |
---|---|
Тема | C function taking a relation and returning a similar relation. |
Дата | |
Msg-id | 1104765792.4286.16.camel@sam обсуждение исходный текст |
Список | pgsql-general |
Hi, Please CC me as I'm not on the list. I'm trying to write a closed frequent itemset data mining custom function for postgresql. The optimal interface for this function would be something like the following: CREATE OR REPLACE FUNCTION cfi( relation, integer ) RETURNS SETOF record AS 'dmfi', 'cfi' LANGUAGE C IMMUTABLE STRICT; From rom my understanding the "relation" in the first argument will have to become the varchar name of a base table/view as relations can not be directly passed in. The return value is basically the same type as the input relation with a few extra columns added. From looking at dblink it seems that for 'setof record' returning functions one must specify the returned relation information in the SELECT clause every time (examples at end). My attempts at having this extra data use a composite TYPE have failed. If I can specify the returned record type in the C function that would be great, but I'm not sure this is possible. Is there a more appropriate method for this relation -> relation mapping function to be connected to PostgreSQL? CREATE OR REPLACE FUNCTION cfi( varchar, integer ) RETURNS SETOF record AS 'dmfi', 'cfi' LANGUAGE C IMMUTABLE STRICT; # input table is ignored, cfi() generates a single integer column. select * from cfi('input',1) as tt( f1 int ); f1 ---- 13 (1 row) ext=> CREATE TYPE mytype AS (f1 integer); ext=> select * from cfi('fred',1) as tt( a mytype ); ERROR: column "a" has composite type mytype ext=> select * from cfi('fred',1) as tt( mytype ); ERROR: a column definition list is required for functions returning "record"
Вложения
В списке pgsql-general по дате отправления: