SPI_execute_plan(): how to make a Datum to insert type inet ?

From: Alex Vinogradovs <AVinogradovs(at)Clearpathnet(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: SPI_execute_plan(): how to make a Datum to insert type inet ?
Date: 2008-03-19 18:38:03
Message-ID: 1205951883.9864.17.camel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Guys,

I've got SPI code that performs inserts into some tables. Code works
fine when destination columns are type text, but fails when there
is something different like inet or macaddr. For type inet, following
error message is produced : could not format inet value: Address family
not supported by protocol family, and for type macaddr the value
inserted is corrupted.
I am sure the problem is in how I make the Datum's for the invokation
of prepared plan, but I couldn't find a proper example anywhere. Here
is how I tried to implement it :

SPIPlanPtr plan = NULL;
Oid *types = palloc(sizeof(Oid));

types[0] = INETOID;

if((plan = SPI_prepare("insert into sometable valeues($1)", 1, types))
== NULL) {

// handle the error

}

Datum *params = palloc(sizeof(Datum));
char *nulls = palloc(1);

params[0] = DirectFunctionCall1(textin,
CStringGetDatum(pstrdup("192.168.1.1")));
nulls[0] = ' ';
if(SPI_execute_plan(plan, params, nulls, FALSE, 1) <= 0) {

// handle the error

}

Thanks!

Best regards
Alex Vinogradovs

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2008-03-19 18:48:20 Re: tsearch2 in postgresql 8.3.1 - invalid byte sequence for encoding "UTF8": 0xc3
Previous Message Joshua D. Drake 2008-03-19 18:06:03 Less than two weeks before PostgreSQL Conference: East