| From: | Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it> | 
|---|---|
| To: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> | 
| Subject: | Variadic polymorpic functions | 
| Date: | 2010-01-22 17:40:56 | 
| Message-ID: | 3eff28921001220940l27bd5530ia3b0ae7b3b4777cf@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | John R Pierce | 2010-01-22 17:43:48 | Re: When is the release date for Postgres 8.5? | 
| Previous Message | Bob Pawley | 2010-01-22 17:27:40 | Re: Old/New |