Michael Meskes wrote:

> Is it possible to define a function in language 'C' that needs more
> libraries to work? I've got a small example of a function that works like a
> charm when run against from a binary. However if I put this function inside
> the server and execute it I get
>
> ERROR:  parser: parse error at or near ""
>
> Not exactly an error message that explains itself. :-)
>
> I have put my function into a shared library to load it, but the library
> itself needs other libraries. Is this at all possible?
>
> Michael
> --
> Michael Meskes                         | Go SF 49ers!
> Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
> Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
> Email: Michael@Fam-Meskes.De           | Use PostgreSQL!

That's odd. Would it be possible for you to provide your compiliation/link
statement as well as your CREATE FUNCTION statement? I've a host of functions
which use external libaries that work as expected (on Linux), including doing
some pretty weird stuff.

Mike Mascari



Tue, 15 Feb 2000 03:42:33 -0500
Mike Mascari <mascarm@mascari.com>
Re: [HACKERS] function question yet again
Is it possible to define a function in language 'C' that needs more
libraries to work? I've got a small example of a function that works like a
charm when run against from a binary. However if I put this function inside
the server and execute it I get 

ERROR:  parser: parse error at or near ""

Not exactly an error message that explains itself. :-)

I have put my function into a shared library to load it, but the library
itself needs other libraries. Is this at all possible?

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!

Tue, 15 Feb 2000 13:14:39 +0100
Michael Meskes <meskes@postgresql.org>
function question yet again
Michael Meskes wrote:
> 
> Is it possible to define a function in language 'C' that needs more
> libraries to work? I've got a small example of a function that works like a
> charm when run against from a binary. However if I put this function inside
> the server and execute it I get
> 
> ERROR:  parser: parse error at or near ""
> 
> Not exactly an error message that explains itself. :-)

Actually, it is very suggestive of quoting or escaping errors.
Presumably your statement terminates somewhere where you would not
expect it. 
 
> I have put my function into a shared library to load it, but the library
> itself needs other libraries. Is this at all possible?

If the system knows how to find it, absolutely. That is, whatever you
depend on will have to be in a system or pgsql library directory.  

Sevo

Tue, 15 Feb 2000 15:14:57 +0100
Sevo Stille <sevo@ip23.net>
Re: [HACKERS] function question yet again
On Tue, Feb 15, 2000 at 04:58:49AM -0800, Alfred Perlstein wrote:
> As a temporary hack you may want to try linking the shared object that you
> are creating with the static versions of the third level libraries.

Good idea. Unfottunately it didn't change anything. Using ldd on my shared
library no tells me it is statically linked. But the error message remains
the same.

I tried to write a log file and it appears the function does correctly
connect to the backend but cannot execute the select. IDK however if a
function inside the backend is allowed to create a connection. But if not
how can I send a query over libpq?

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!

Tue, 15 Feb 2000 15:24:30 +0100
Michael Meskes <meskes@postgresql.org>
Re: [HACKERS] function question yet again
On Tue, Feb 15, 2000 at 03:42:33AM -0500, Mike Mascari wrote:
> That's odd. Would it be possible for you to provide your compiliation/link
> statement as well as your CREATE FUNCTION statement? I've a host of functions
> which use external libaries that work as expected (on Linux), including doing
> some pretty weird stuff.

I attach both files. My intend was to get this thing going by using ecpg.
I'm not sure anymore if this is at all possible.

Michael

-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!
Tue, 15 Feb 2000 15:26:20 +0100
Michael Meskes <meskes@postgreSQL.org>
Re: [HACKERS] function question yet again
Michael Meskes wrote:
> 
> I attach both files. My intend was to get this thing going by using
> ecpg.
> I'm not sure anymore if this is at all possible.
> 
> Michael
> 
> --
> Michael Meskes                         | Go SF 49ers!
> Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
> Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
> Email: Michael@Fam-Meskes.De           | Use PostgreSQL!

Wow. I'm not quite sure why it shouldn't work, but I've never
reconnected on the server side through libpq. Instead, I've
always used the SPI interface sequence of:

SPI_connect()
SPI_exec()
SPI_getvalue()
SPI_finish()

I think I've tried in the past to reconnect on the server side
through libpq but it always resulted in a core dump of the
running backend.

Sorry I'm no more help then that, 

Mike Mascari

Tue, 15 Feb 2000 10:09:35 -0500
Mike Mascari <mascarm@mascari.com>
Re: [HACKERS] function question yet again
On Tue, Feb 15, 2000 at 03:14:57PM +0100, Sevo Stille wrote:
> Actually, it is very suggestive of quoting or escaping errors.
> Presumably your statement terminates somewhere where you would not
> expect it. 

Okay. But why does it work when run from outside the backend?

> If the system knows how to find it, absolutely. That is, whatever you
> depend on will have to be in a system or pgsql library directory.  

I made my shared lib not depend on any other lib, but nothing changes.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!

Tue, 15 Feb 2000 20:21:21 +0100
Michael Meskes <meskes@postgreSQL.org>
Re: [HACKERS] function question yet again
Mike Mascari <mascarm@mascari.com> writes:
> Wow. I'm not quite sure why it shouldn't work, but I've never
> reconnected on the server side through libpq. Instead, I've
> always used the SPI interface sequence of:
> SPI_connect()
> SPI_exec()
> SPI_getvalue()
> SPI_finish()

SPI is the recommended interface for server-side addon code, I think.

> I think I've tried in the past to reconnect on the server side
> through libpq but it always resulted in a core dump of the
> running backend.

Bear in mind that libpq is not present in the backend.  If you load
a library containing your code + libpq and then try to do something
via libpq, what will happen is that libpq will contact the postmaster,
fire up a new backend, and send all your queries to that other backend.
Probably not quite what you had in mind, and I could imagine it leading
to deadlock problems against your own backend.  (But I don't see why it
would cause the particular error Michael is complaining of; that still
looks like it might be a newline-versus-carriage-return kind of bug.)

I believe that long ago, there was code in the backend that presented
a libpq-equivalent interface for queries originating from loaded
libraries, but that facility hasn't been maintained and probably
doesn't work at all anymore.

			regards, tom lane

Tue, 15 Feb 2000 16:29:25 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: [HACKERS] function question yet again 
On Tue, Feb 15, 2000 at 04:29:25PM -0500, Tom Lane wrote:
> SPI is the recommended interface for server-side addon code, I think.

Okay, I see. That means my try to use ECPG to create a function is not
supposed to work. Gheez, I would have liked it.

> Bear in mind that libpq is not present in the backend.  If you load
> a library containing your code + libpq and then try to do something
> via libpq, what will happen is that libpq will contact the postmaster,
> fire up a new backend, and send all your queries to that other backend.
> Probably not quite what you had in mind, and I could imagine it leading
> to deadlock problems against your own backend.  (But I don't see why it
> would cause the particular error Michael is complaining of; that still
> looks like it might be a newline-versus-carriage-return kind of bug.)

Right. Since the function does only a select and noone else is working on
that database it shouldn't deadlock either.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!

Wed, 16 Feb 2000 08:14:22 +0100
Michael Meskes <meskes@postgreSQL.org>
Re: [HACKERS] function question yet again
Michael Meskes wrote:
> 
> On Tue, Feb 15, 2000 at 04:29:25PM -0500, Tom Lane wrote:
> > SPI is the recommended interface for server-side addon code, I think.
> 
> Okay, I see. That means my try to use ECPG to create a function is not
> supposed to work. Gheez, I would have liked it.

It should be possible to create a SPI based libecpg.so! Though I don't
know if it is worth the effort (besides getting portable server code
(WOW)!) Hmmm. I come to like this idea.

I don't have any ideas on the deadlock, though.

Christof


Thu, 17 Feb 2000 05:08:08 +0100
Christof Petig <christof.petig@wtal.de>
Re: [HACKERS] function question yet again
On Thu, Feb 17, 2000 at 05:08:08AM +0100, Christof Petig wrote:
> It should be possible to create a SPI based libecpg.so! Though I don't
> know if it is worth the effort (besides getting portable server code
> (WOW)!) Hmmm. I come to like this idea.

I really do like this idea to. But it is not realistic to get this one
finished before 7.0 though.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!

Thu, 17 Feb 2000 20:44:05 +0100
Michael Meskes <meskes@postgreSQL.org>
Re: [HACKERS] function question yet again