Обсуждение: Looking for pure C function APIs for server extension: language handler and SPI

Поиск
Список
Период
Сортировка

What I need (to find or create) is a ‘pure’ C language API to support a Postgres server extension. By ‘pure’ I mean one that has no knowledge of Postgres internals and that could be called by a generic interface provided by some other tool that can support C language APIs.

 

The reason is that I’m looking to integrate a new language (Andl) into Postgres. To do that I need to find or create a ‘pure’ C-language API to interface with:

1.       The generic language call interface (pl_language_handler), which must handle conversion of Incoming language call parameters and outgoing language call return value.

1.       The backend query execution interface (SPI), which must handle conversion of outgoing query parameters and incoming query result values.

 

There are 5 generic data types: boolean, binary (blob), number (decimal/real/integer), text (string/varchar), time (date/datetime). Each data type needs to be converted between the Postgres internal data types (Datum) and some intermediate data type that can be passed through a pure C API. In my case that will be C# (MS or Mono), but others might want to use Java or whatever.

 

These conversion tasks are identical to those needed to implement an ODBC/JDBC or similar interface, but one bound directly to the server and not going through a client (socket) connection. I have already done this successfully with Sqlite, which already provides a pure C server API and excellent documentation to go with it, so I know what it might look like.

 

FYI apart from these two APIs (and their 4x5 conversions), the only other thing needed is some SQL code generation and I expect to have a working language of considerable power.

 

Any help, suggestions, pointers much appreciated.

 

Regards

David M Bennett FACS


Andl - A New Database Language - andl.org

 

Re: Looking for pure C function APIs for server extension: language handler and SPI

От
John McKown
Дата:
On Mon, Feb 29, 2016 at 5:55 PM, <david@andl.org> wrote:

What I need (to find or create) is a ‘pure’ C language API to support a Postgres server extension. By ‘pure’ I mean one that has no knowledge of Postgres internals and that could be called by a generic interface provided by some other tool that can support C language APIs.


​Well, since nobody else has replied yet, have you read: http://www.postgresql.org/docs/9.5/interactive/libpq.html

libpq is the C callable API which communicates with the PostgreSQL server. There is a "shared object" and a normal library which can be "statically linked". But that's really all that _I_ know about it.
 

 

The reason is that I’m looking to integrate a new language (Andl) into Postgres. To do that I need to find or create a ‘pure’ C-language API to interface with:

1.       The generic language call interface (pl_language_handler), which must handle conversion of Incoming language call parameters and outgoing language call return value.

1.       The backend query execution interface (SPI), which must handle conversion of outgoing query parameters and incoming query result values.

 

There are 5 generic data types: boolean, binary (blob), number (decimal/real/integer), text (string/varchar), time (date/datetime). Each data type needs to be converted between the Postgres internal data types (Datum) and some intermediate data type that can be passed through a pure C API. In my case that will be C# (MS or Mono), but others might want to use Java or whatever.

 

These conversion tasks are identical to those needed to implement an ODBC/JDBC or similar interface, but one bound directly to the server and not going through a client (socket) connection. I have already done this successfully with Sqlite, which already provides a pure C server API and excellent documentation to go with it, so I know what it might look like.

 

FYI apart from these two APIs (and their 4x5 conversions), the only other thing needed is some SQL code generation and I expect to have a working language of considerable power.

 

Any help, suggestions, pointers much appreciated.

 

Regards

David M Bennett FACS


Andl - A New Database Language - andl.org

 


--
The man has the intellect of a lobotomized turtle.

Maranatha! <><
John McKown

Re: Looking for pure C function APIs for server extension: language handler and SPI

От
John R Pierce
Дата:
On 2/29/2016 3:55 PM, david@andl.org wrote:

What I need (to find or create) is a ‘pure’ C language API to support a Postgres server extension. By ‘pure’ I mean one that has no knowledge of Postgres internals and that could be called by a generic interface provided by some other tool that can support C language APIs.

 

The reason is that I’m looking to integrate a new language (Andl) into Postgres. To do that I need to find or create a ‘pure’ C-language API to interface with:

1.       The generic language call interface (pl_language_handler), which must handle conversion of Incoming language call parameters and outgoing language call return value.

1.       The backend query execution interface (SPI), which must handle conversion of outgoing query parameters and incoming query result values.



by "server extension" do you mean, you want to use Andi as a "PL/Andi" so you can write stored procedures i Andi callable within SQL queries?

or do you mean, you want your Andi programs to be able to execute normal postgresql queries as a regular client ? 


for the first, see
http://www.postgresql.org/docs/9.5/static/plhandler.html

for the latter, see
http://www.postgresql.org/docs/9.5/static/libpq.html



-- 
john r pierce, recycling bits in santa cruz

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of John McKown
Sent: Wednesday, 2 March 2016 1:03 PM
To: david@andl.org
Cc: pgsql-general-owner+M220260=david=andl.org@postgresql.org; Postgres General <pgsql-general@postgresql.org>
Subject: Re: [GENERAL] Looking for pure C function APIs for server extension: language handler and SPI

 

On Mon, Feb 29, 2016 at 5:55 PM, <david@andl.org> wrote:

What I need (to find or create) is a ‘pure’ C language API to support a Postgres server extension. By ‘pure’ I mean one that has no knowledge of Postgres internals and that could be called by a generic interface provided by some other tool that can support C language APIs.

 

​Well, since nobody else has replied yet, have you read: http://www.postgresql.org/docs/9.5/interactive/libpq.html

 

Thanks for noticing! Yes, but this is a server extension and libpq is client side. I want to use the generic language call handler and SPI query interface on the server, not client side.

 

libpq is the C callable API which communicates with the PostgreSQL server. There is a "shared object" and a normal library which can be "statically linked". But that's really all that _I_ know about it.

 

[dmb>]

​ 

 

The reason is that I’m looking to integrate a new language (Andl) into Postgres. To do that I need to find or create a ‘pure’ C-language API to interface with:

1.       The generic language call interface (pl_language_handler), which must handle conversion of Incoming language call parameters and outgoing language call return value.

1.       The backend query execution interface (SPI), which must handle conversion of outgoing query parameters and incoming query result values.

 

There are 5 generic data types: boolean, binary (blob), number (decimal/real/integer), text (string/varchar), time (date/datetime). Each data type needs to be converted between the Postgres internal data types (Datum) and some intermediate data type that can be passed through a pure C API. In my case that will be C# (MS or Mono), but others might want to use Java or whatever.

 

These conversion tasks are identical to those needed to implement an ODBC/JDBC or similar interface, but one bound directly to the server and not going through a client (socket) connection. I have already done this successfully with Sqlite, which already provides a pure C server API and excellent documentation to go with it, so I know what it might look like.

 

FYI apart from these two APIs (and their 4x5 conversions), the only other thing needed is some SQL code generation and I expect to have a working language of considerable power.

 

Any help, suggestions, pointers much appreciated.

 

Regards

David M Bennett FACS


Andl - A New Database Language - andl.org

 

 

--

The man has the intellect of a lobotomized turtle.


Maranatha! <><
John McKown

Re: Looking for pure C function APIs for server extension: language handler and SPI

От
"David Bennett"
Дата:

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of John McKown
Sent: Wednesday, 2 March 2016 1:03 PM
To: david@andl.org
Cc: pgsql-general-owner+M220260=david=andl.org@postgresql.org; Postgres General <pgsql-general@postgresql.org>
Subject: Re: [GENERAL] Looking for pure C function APIs for server extension: language handler and SPI

 

On Mon, Feb 29, 2016 at 5:55 PM, <david@andl.org> wrote:

What I need (to find or create) is a ‘pure’ C language API to support a Postgres server extension. By ‘pure’ I mean one that has no knowledge of Postgres internals and that could be called by a generic interface provided by some other tool that can support C language APIs.

 

​Well, since nobody else has replied yet, have you read: http://www.postgresql.org/docs/9.5/interactive/libpq.html

 

Thanks for noticing! Yes, but this is a server extension and libpq is client side. I want to use the generic language call handler and SPI query interface on the server, not client side.

 

libpq is the C callable API which communicates with the PostgreSQL server. There is a "shared object" and a normal library which can be "statically linked". But that's really all that _I_ know about it.

 

[dmb>]

​ 

 

The reason is that I’m looking to integrate a new language (Andl) into Postgres. To do that I need to find or create a ‘pure’ C-language API to interface with:

1.       The generic language call interface (pl_language_handler), which must handle conversion of Incoming language call parameters and outgoing language call return value.

1.       The backend query execution interface (SPI), which must handle conversion of outgoing query parameters and incoming query result values.

 

There are 5 generic data types: boolean, binary (blob), number (decimal/real/integer), text (string/varchar), time (date/datetime). Each data type needs to be converted between the Postgres internal data types (Datum) and some intermediate data type that can be passed through a pure C API. In my case that will be C# (MS or Mono), but others might want to use Java or whatever.

 

These conversion tasks are identical to those needed to implement an ODBC/JDBC or similar interface, but one bound directly to the server and not going through a client (socket) connection. I have already done this successfully with Sqlite, which already provides a pure C server API and excellent documentation to go with it, so I know what it might look like.

 

FYI apart from these two APIs (and their 4x5 conversions), the only other thing needed is some SQL code generation and I expect to have a working language of considerable power.

 

Any help, suggestions, pointers much appreciated.

 

Regards

David M Bennett FACS


Andl - A New Database Language - andl.org

 

 

--

The man has the intellect of a lobotomized turtle.


Maranatha! <><
John McKown

Re: Looking for pure C function APIs for server extension: language handler and SPI

От
"David Bennett"
Дата:

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of John R Pierce
Sent: Wednesday, 2 March 2016 1:30 PM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Looking for pure C function APIs for server extension: language handler and SPI

 

On 2/29/2016 3:55 PM, david@andl.org wrote:

What I need (to find or create) is a ‘pure’ C language API to support a Postgres server extension. By ‘pure’ I mean one that has no knowledge of Postgres internals and that could be called by a generic interface provided by some other tool that can support C language APIs.

 

The reason is that I’m looking to integrate a new language (Andl) into Postgres. To do that I need to find or create a ‘pure’ C-language API to interface with:

1.       The generic language call interface (pl_language_handler), which must handle conversion of Incoming language call parameters and outgoing language call return value.

1.       The backend query execution interface (SPI), which must handle conversion of outgoing query parameters and incoming query result values.



by "server extension" do you mean, you want to use Andi as a "PL/Andi" so you can write stored procedures i Andi callable within SQL queries?

 

Yes, more or less. The end result will probably be a little different for reasons that don’t matter here, but that would be a possible outcome.

 

I’ve gone through all the existing PL/xxx implementations and they all finish up with 10K lines of laborious C code. That’s 6 months’ work! I know I can write the code much faster in C++ or C#, but many of the access routines are exposed only as ‘impure’ C code such as macros, #defines, global variables, etc. I want to write a minimum layer of C code, exposing a ‘pure’ C API, and do most of the work (eg conversions), in a higher level language.

 

Sorry if I’m not explaining it well, but it’s not an easy thing to get across.

or do you mean, you want your Andi programs to be able to execute normal postgresql queries as a regular client ? 

 

No, not this. Server-side only.


for the first, see
http://www.postgresql.org/docs/9.5/static/plhandler.html

 

I know it well. I have a working sample [but it keeps crashing. The rules are not easy to work out and the docs are thin.]

 

I was hoping to turn up some project or sample that would get me further along, and faster.


for the latter, see
http://www.postgresql.org/docs/9.5/static/libpq.html




-- 
john r pierce, recycling bits in santa cruz