C function taking a relation and returning a similar relation.

From: Ben Martin <monkeyiq(at)users(dot)sourceforge(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: C function taking a relation and returning a similar relation.
Date: 2005-01-03 15:23:12
Message-ID: 1104765792.4286.16.camel@sam
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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"

Browse pgsql-general by date

  From Date Subject
Next Message Frank D. Engel, Jr. 2005-01-03 16:53:44 Generating unique values for TEXT columns
Previous Message Joe Conway 2005-01-03 15:20:54 Re: Merging Data from Multiple DB