PL/C functions

Started by Dennis Gearonover 22 years ago11 messagesgeneral
Jump to latest
#1Dennis Gearon
gearond@cvc.net

Is it possible to write functions for PL/C that have variable argument lists?

I.E.
UPPER( arg )
UPPER( arg, encoding_list )

LOWER( arg )
LOWER( arg, encoding_list )

SUBSTR( arg, arg, arg )
SUBSTR( arg, arg, arg, encoding_list );

Obviously, these would have to take the place of the original functions, is that possible?

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Dennis Gearon (#1)
Re: PL/C functions

Dennis Gearon writes:

Is it possible to write functions for PL/C that have variable argument lists?

You cannot write functions with variable argument lists in any language.

--
Peter Eisentraut peter_e@gmx.net

#3Dennis Gearon
gearond@cvc.net
In reply to: Peter Eisentraut (#2)
Re: PL/C functions

Uuuuuuuuuuuh, C++ can do it, PHP can do it, JAVA can do it, I just want to know if PL/C can do it for UDF's.

Peter Eisentraut wrote:

Show quoted text

Dennis Gearon writes:

Is it possible to write functions for PL/C that have variable argument lists?

You cannot write functions with variable argument lists in any language.

#4Dennis Gearon
gearond@cvc.net
In reply to: Peter Eisentraut (#2)
#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Gearon (#3)
Re: PL/C functions

Dennis Gearon <gearond@cvc.net> writes:

Uuuuuuuuuuuh, C++ can do it, PHP can do it, JAVA can do it, I just
want to know if PL/C can do it for UDF's.

We have no animal called "PL/C". Kindly be more clear about what your
question is.

regards, tom lane

#6Dennis Gearon
gearond@cvc.net
In reply to: Tom Lane (#5)
Re: PL/C functions

User defined functions written in C/C++? That's _NOT_ known as PL/C? sorry for the confusion.

Tom Lane wrote:

Show quoted text

Dennis Gearon <gearond@cvc.net> writes:

Uuuuuuuuuuuh, C++ can do it, PHP can do it, JAVA can do it, I just
want to know if PL/C can do it for UDF's.

We have no animal called "PL/C". Kindly be more clear about what your
question is.

regards, tom lane

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Gearon (#6)
Re: PL/C functions

Dennis Gearon <gearond@cvc.net> writes:

We have no animal called "PL/C". Kindly be more clear about what your
question is.

User defined functions written in C/C++?

Okay. The answer is:

1. There is no provision for a single pg_proc entry to have a variable
number of arguments.

2. You can make multiple pg_proc entries referencing the same C
function. The C function can find out how many arguments it was
actually passed (use PG_NARGS()).

So you could make several different pg_proc entries and get the desired
effect, at some tedium.

Joe Conway has posted a few examples using this approach, IIRC.

regards, tom lane

#8Joe Conway
mail@joeconway.com
In reply to: Tom Lane (#7)
Re: PL/C functions

Tom Lane wrote:

1. There is no provision for a single pg_proc entry to have a variable
number of arguments.

2. You can make multiple pg_proc entries referencing the same C
function. The C function can find out how many arguments it was
actually passed (use PG_NARGS()).

So you could make several different pg_proc entries and get the desired
effect, at some tedium.

Joe Conway has posted a few examples using this approach, IIRC.

See contrib/dblink in 7.4beta -- there are several functions using this
method, e.g. dblink_connect().

Joe

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Gearon (#1)
Re: PL/C functions

Dennis Gearon <gearond@cvc.net> writes:

One final note on this topic, (for me), if I write a C function that changes one of the LOCALES:

... you will probably break things. Read the comments in
/src/backend/utils/adt/pg_locale.c.

regards, tom lane

#10Dennis Gearon
gearond@cvc.net
In reply to: Joe Conway (#8)
Re: PL/C functions

One final note on this topic, (for me), if I write a C function that changes one of the LOCALES:

1/ Will it change the LOCALE at all?
2/ Does it change it for the whole program, affecting other, asynchronous
execution within any of the modules of the dbase?

Joe Conway wrote:

Show quoted text

Tom Lane wrote:

1. There is no provision for a single pg_proc entry to have a variable
number of arguments.

2. You can make multiple pg_proc entries referencing the same C
function. The C function can find out how many arguments it was
actually passed (use PG_NARGS()).

So you could make several different pg_proc entries and get the desired
effect, at some tedium.

Joe Conway has posted a few examples using this approach, IIRC.

See contrib/dblink in 7.4beta -- there are several functions using this
method, e.g. dblink_connect().

Joe

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

#11Dennis Gearon
gearond@cvc.net
In reply to: Tom Lane (#9)
Re: PL/C functions

This is where a variable argument list for a function would come in handy, if ISO C had such for 'strxfrm()'. The locale could be supplied INLINE, instead of taken from the machine LOCALE. Maybe I'll just copy the library functions and change them to use an extra argument for LOCALE.

Tom Lane wrote:

Show quoted text

Dennis Gearon <gearond@cvc.net> writes:

One final note on this topic, (for me), if I write a C function that changes one of the LOCALES:

... you will probably break things. Read the comments in
/src/backend/utils/adt/pg_locale.c.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly