Search Postgresql Archives

Variadic polymorpic functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux