Thread: PL/C functions

PL/C functions

From
Dennis Gearon
Date:
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?


Re: PL/C functions

From
Dennis Gearon
Date:
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:

> 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.
>


Re: PL/C functions

From
Peter Eisentraut
Date:
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

Re: PL/C functions

From
Dennis Gearon
Date:
I haven't seen anything saying it's possible to use either default arguments or variable argument lists in C functions
usediin PL/C, but otherwise: 


c++
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=variable+argument+list+function+c%2B%2B&btnG=Google+Search

php
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=variable+argument+list++function+php&btnG=Google+Search

JAVA
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=variable+argument+list+java&btnG=Google+Search

perl
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=variable+argument+list+function+java&btnG=Google+Search

python
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=variable+argument+list+function+python&btnG=Google+Search

Peter Eisentraut wrote:

> 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.
>


Re: PL/C functions

From
Tom Lane
Date:
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

Re: PL/C functions

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

Tom Lane wrote:

> 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
>


Re: PL/C functions

From
Tom Lane
Date:
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

Re: PL/C functions

From
Joe Conway
Date:
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


Re: PL/C functions

From
Dennis Gearon
Date:
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:

> 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
>


Re: PL/C functions

From
Tom Lane
Date:
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

Re: PL/C functions

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

Tom Lane wrote:

> 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
>