Subject: Function C and INOUT parameters

From: Ben Ali Rachid <[email-masked]>
Date: Tue, 24 Mar 2009 16:54:30 +0000 (GMT)

Hello, 

I posted my problem (on pgsql-interfaces list) about the INOUT parameters on PostgreSQL 8.3.6 (Win32), but without success. I re-post my question here, while hoping to have more success.

When I use a function with one INOUT (or OUT) parameter like below, everyting is OK.

CREATE OR REPLACE FUNCTION add_one(INOUT arg integer)

RETURNS integer  AS '$libdir/myDLL.dll', 'add_one'

LANGUAGE 'c' VOLATILE STRICT ;

// In 'myDLL'
void add_one(int arg)

{

	arg = arg + 1 ;

}

select * from add_one(10) ;  // OK

But when I use 2 or more INOUT (or OUT) parameters like below, the server crashes with exception 0xC0000005 (access violation). 

CREATE OR REPLACE FUNCTION add_one(INOUT arg1 integer, INOUT arg2 integer)

RETURNS record  AS '$libdir/myDLL.dll', 'add_one'

LANGUAGE 'c' VOLATILE STRICT ;

void add_one(int arg1, int arg2)

{

	arg1 = arg1 + 1 ;

	arg2 = arg2 + 1 ;

}

select * from add_one(10, 20);  // CRASH

I probably understood something wrong with the INOUT parameter. Is there someone to help me ? Thanks.

---

From: Tom Lane <[email-masked]>
Date: Tue, 24 Mar 2009 14:11:07 -0400

> I posted my problem (on pgsql-interfaces list) about the INOUT parameters on PostgreSQL 8.3.6 (Win32), but without success. I re-post my question here, while hoping to have more success.

You apparently have no understanding at all of how parameters are passed
to and from C-language functions in Postgres :-(.  Start here:

http://www.postgresql.org/docs/8.3/static/xfunc-c.html

and note that any situation involving multiple OUT parameters is handled
as returning an anonymous composite type.  There are a number of
useful examples in the contrib modules.

			regards, tom lane

---

From: Greg Stark <[email-masked]>
Date: Tue, 24 Mar 2009 18:11:17 +0000

On Tue, Mar 24, 2009 at 4:54 PM, Ben Ali Rachid <[email-masked]> wrote:
> Hello,
>
> I posted my problem (on pgsql-interfaces list) about the INOUT parameters on
> PostgreSQL 8.3.6 (Win32), but without success. I re-post my question here,
> while hoping to have more success.

Personally I'm of the opinion we should eliminate most of these
duplicative mailing lists like -performance and -interfaces and just
use -general. I don't see that having multiple lists for user
questions helps either the users or the answerers due to just this
type of problem.

> LANGUAGE 'c' VOLATILE STRICT ;

a) you should probably be using V1 calling api rather than V0. see

http://www.postgresql.org/docs/8.3/interactive/xfunc-c.html#AEN40901

b) you need to arrange for the C function to return a record with all
the returned fields. You can't just set the parameters to new values
and return void.

The api to return a record is at:

http://www.postgresql.org/docs/8.3/interactive/xfunc-c.html#AEN41361

-- 
greg

---

From: Robert Haas <[email-masked]>
Date: Tue, 24 Mar 2009 14:21:22 -0400

> questions helps either the users or the answerers due to just this

-1.  I don't read -general; I do read -performance.  The S/N ratio is
high enough to make it worth the time it takes; I don't think that
would be true on -general.

...Robert

---

From: Josh Berkus <[email-masked]>
Date: Tue, 24 Mar 2009 18:03:15 -0700

> questions helps either the users or the answerers due to just this

... and instead drive new users away by forcing them to sign up for one 
massive 400 posts/day list?

I'm not sure about -interfaces, but -performance, -sql, -jdbc and others 
definitely have specific audiences and themes which they are already 
handling a *lot* of traffic for.

--Josh

---

From: Tom Lane <[email-masked]>
Date: Tue, 24 Mar 2009 21:18:44 -0400

> handling a *lot* of traffic for.

It does look like -interfaces is dying: almost no traffic, and what
questions it does get are off-topic more often than not.  Partly this
is because the -jdbc, -odbc, and -php lists suck away all the traffic
about those interfaces, leaving not much.  So we could kill -interfaces
without much loss IMHO.

The other global lists seem to be in good health from what I can see.
Can't speak to the regional or user-group lists, I don't follow them.

			regards, tom lane

---

From: Josh Berkus <[email-masked]>
Date: Tue, 24 Mar 2009 18:34:35 -0700

Tom,

> Can't speak to the regional or user-group lists, I don't follow them.

Those have specific reasons to survive regardless of traffic level.

--Josh

---

From: Peter Eisentraut <[email-masked]>
Date: Wed, 25 Mar 2009 13:46:53 +0200

> about those interfaces, leaving not much.  So we could kill -interfaces

It was supposed to have been killed already, as per last year's dev 
meeting and subsequent discussion.  Someone just needs to do it.

---

From: Alvaro Herrera <[email-masked]>
Date: Wed, 25 Mar 2009 11:11:08 -0400

> meeting and subsequent discussion.  Someone just needs to do it.

Okay, I've moved it to the inactive group; it already shows up as such
in archives, and www will be updated as soon as it rebuilds and
propagates to the mirrors.

As for actually shutting it down in Majordomo, Marc is the man.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

---

From: Josh Berkus <[email-masked]>
Date: Wed, 25 Mar 2009 11:19:57 -0700

> As for actually shutting it down in Majordomo, Marc is the man.

Might want to make an announcement on that list first.

--Josh

---

From: Alvaro Herrera <[email-masked]>
Date: Wed, 25 Mar 2009 15:17:23 -0400

> Might want to make an announcement on that list first.

http://archives.postgresql.org/pgsql-interfaces/2008-07/msg00002.php

---

From: Josh Berkus <[email-masked]>
Date: Wed, 25 Mar 2009 12:23:13 -0700

> http://archives.postgresql.org/pgsql-interfaces/2008-07/msg00002.php

That was 6 months ago.  I doubt anyone remembers it.  Make another 
announcement, so that when people get the "unsubscribed" announcement, 
they're not confused.

--Josh

---

From: Alvaro Herrera <[email-masked]>
Date: Wed, 25 Mar 2009 17:50:53 -0400

> announcement, so that when people get the "unsubscribed" announcement,  

Done.

---

From: Tom Lane <[email-masked]>
Date: Wed, 25 Mar 2009 17:55:06 -0400

> Done.

BTW, what was the reason we didn't pull the trigger before, when we
retired the other lists?  Just an oversight?

			regards, tom lane

---

From: "Marc G. Fournier" <[email-masked]>
Date: Thu, 26 Mar 2009 00:43:07 -0300 (ADT)

Please clarify what you want done on the majordomo side ... I saw one 
comment about unsub'ng everyone ... for archive purposes, this makes 
sense, I just want to make sure before I blow them all away (and I will 
unsubscribe them without having a blast of emails go out to them) ....

I will also mark the list as 'inactive' ...

On Wed, 25 Mar 2009, Alvaro Herrera wrote:

> Sent via pgsql-www mailing list ([email-masked])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-www
>

----
Marc G. Fournier           Hub.Org Networking Services (http://www.hub.org)
Email . [email-masked]                              MSN . [email-masked]
Yahoo . yscrappy               Skype: hub.org        ICQ . 7615664

---

From: Peter Eisentraut <[email-masked]>
Date: Thu, 26 Mar 2009 08:24:36 +0200

> retired the other lists?  Just an oversight?

Because the same people who complained just now complained back then as well.  
So we retired the lists without objections first.