Variadic polymorpic functions - Mailing list pgsql-general

From Vincenzo Romano
Subject Variadic polymorpic functions
Date
Msg-id 3eff28921001220940l27bd5530ia3b0ae7b3b4777cf@mail.gmail.com
Whole thread Raw
Responses Re: Variadic polymorpic functions  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi all.

I'm using the printf() function as seen here:
http://wiki.postgresql.org/wiki/Sprintf

What I see is that when I call that function with just 1 argument,
it's always OK.
As here:
-- code
mp1=# SELECT printf( '%',now() );
            printf
-------------------------------
 2010-01-22 18:31:24.045347+01
(1 row)

Time: 0.565 ms
tmp1=# SELECT printf( '%',3.1415926535 );
    printf
--------------
 3.1415926535
(1 row)

Time: 0.529 ms
-- end code

As soon as I put a second argument I get an arror:
-- code
tmp1=# SELECT printf( '% %',now(),42 );
ERROR:  function printf(unknown, timestamp with time zone, integer)
does not exist
LINE 1: SELECT printf( '% %',now(),42 );
               ^
HINT:  No function matches the given name and argument types. You
might need to add explicit type casts.
-- end code

which disapperas as soon as I cast all the parameters to text:
-- code
tmp1=# SELECT printf( '% %',now()::text,42::text );
              printf
----------------------------------
 2010-01-22 18:33:10.357877+01 42
(1 row)

Time: 1.956 ms
-- end code
or when all argument types have the same type:
-- code
tmp1=# SELECT printf( '% %',now(),now() );
                           printf
-------------------------------------------------------------
 2010-01-22 18:34:07.055344+01 2010-01-22 18:34:07.055344+01
(1 row)

Time: 0.589 ms
-- end code
I was expecting that a "variadic polymorphic" function was able to
accept a "variable number of arguments of different types" (a-la C),
while it looks to me that it actually means "variable number of
arguments of a single type".

Is this limitation intentional or is it a bug?

--
Vincenzo Romano
NotOrAnd Information Technologies
NON QVIETIS MARIBVS NAVTA PERITVS

pgsql-general by date:

Previous
From: "Bob Pawley"
Date:
Subject: Re: Old/New
Next
From: John R Pierce
Date:
Subject: Re: When is the release date for Postgres 8.5?