Re: RfD: more powerful "any" types - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: RfD: more powerful "any" types
Date
Msg-id 162867790909101315v40579de5uf470c2c2d4c956c@mail.gmail.com
Whole thread Raw
In response to Re: RfD: more powerful "any" types  (Hannu Krosing <hannu@2ndQuadrant.com>)
Responses Re: RfD: more powerful "any" types
Re: RfD: more powerful "any" types
List pgsql-hackers
2009/9/10 Hannu Krosing <hannu@2ndquadrant.com>:
> On Thu, 2009-09-10 at 21:35 +0200, Pavel Stehule wrote:
>> 2009/9/10 Tom Lane <tgl@sss.pgh.pa.us>:
>> > Pavel Stehule <pavel.stehule@gmail.com> writes:
>> >> I don't afraid about crashing. Simply I have not idea what sql
>> >> sprintf's behave in case:
>> >
>> >> SELECT sprintf('some %s', 10)
>> >
>> > That one I don't think is hard --- coerce the input type to text and
>> > print the string.
>> >
>> >> SELECT sprintf('some %d', 10::mycustomtype)
>> >
>> > For the formats that presume an integer or float input in C, perhaps
>> > we could coerce to numeric (failing if that fails) and then print
>> > appropriately.  Or maybe int or float8 would be more appropriate
>> > conversion targets.
>>
>> it's possible - so format tags doesn't mean data type, but it means
>> "try to drow it as type" - etc invisible explicit casting.
>
>
> what is the difference between these two ?

first is coming from C and has C semantic - there is only one possible
tag (without binary compatible types) - you cannot use %s for numbers,
and %d for strings is some specific value.

sprintf("%d", "10") - show address of static string "10"

second is Tom's proposal. More dynamic. Tag specify target type.

so sprintf('%d', '10') show 10 with possible width manipulation operations

Pavel

>
>> It could work, but it doesn't look like SQL.
>
> but we do it all over the place if another type is needed and CAST
> exists for getting it
>
> --
> Hannu Krosing   http://www.2ndQuadrant.com
> PostgreSQL Scalability and Availability
>   Services, Consulting and Training
>
>
>


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: RfD: more powerful "any" types
Next
From: Pavel Stehule
Date:
Subject: Re: RfD: more powerful "any" types