How to access large objects in Postgresql c-language functions?

Started by Spiros Ioannouabout 11 years ago6 messagesgeneral
Jump to latest
#1Spiros Ioannou
sivann@inaccess.com

I'm writing a c-language user defined function for postgresql 9.3.5. I
didn't use pl/pgsql or pl/python because part of it needs to be written in
C for speed.

The function gets an existing OID as an argument. How can I access & modify
the OID data from within the c-language function? I can't find any docs for
that!

Thanks,

-Spiros

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Spiros Ioannou (#1)
Re: How to access large objects in Postgresql c-language functions?

Hi

you can use a lo_* (lo_open, lo_close, ...) functions called via
FirectFunctionCall

http://michael.otacoo.com/postgresql-2/playing-with-large-objects-in-postgres/
http://www.postgresql.org/docs/9.3/static/lo-interfaces.html

Regards

Pavel Stehule

2015-01-26 20:19 GMT+01:00 Spiros Ioannou <sivann@inaccess.com>:

Show quoted text

I'm writing a c-language user defined function for postgresql 9.3.5. I
didn't use pl/pgsql or pl/python because part of it needs to be written in
C for speed.

The function gets an existing OID as an argument. How can I access &
modify the OID data from within the c-language function? I can't find any
docs for that!

Thanks,

-Spiros

#3Spiros Ioannou
sivann@inaccess.com
In reply to: Pavel Stehule (#2)
Re: How to access large objects in Postgresql c-language functions?

But these need a connection to the postgresql backend. It seems an overkill
for postgresql to connect to itself, I would prefer something more optimal.
It seems for now that reading libpq's source code is the only way to go.

Regards,

Spiros

#4John R Pierce
pierce@hogranch.com
In reply to: Spiros Ioannou (#3)
Re: How to access large objects in Postgresql c-language functions?

On 1/26/2015 11:54 AM, Spiros Ioannou wrote:

But these need a connection to the postgresql backend. It seems an
overkill for postgresql to connect to itself, I would prefer something
more optimal. It seems for now that reading libpq's source code is the
only way to go.

you use the SPI functions to execute queries from within a C function.

http://www.postgresql.org/docs/current/static/spi.html

--
john r pierce 37N 122W
somewhere on the middle of the left coast

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Spiros Ioannou (#3)
Re: How to access large objects in Postgresql c-language functions?

2015-01-26 20:54 GMT+01:00 Spiros Ioannou <sivann@inaccess.com>:

But these need a connection to the postgresql backend. It seems an
overkill for postgresql to connect to itself, I would prefer something more
optimal. It seems for now that reading libpq's source code is the only way
to go.

No, it doesn't need - you can call these functions via DirectFunctionCall
interface

you can look to contrib/lo module for example

Regards

Pavel

Show quoted text

Regards,

Spiros

#6Spiros Ioannou
sivann@inaccess.com
In reply to: Pavel Stehule (#5)
Re: How to access large objects in Postgresql c-language functions?

Thanks, that's interesting, I will look into that.
Regards,
-Spiros