From: | Hannu Krosing <hannu(at)2ndQuadrant(dot)com> |
---|---|
To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: RfD: more powerful "any" types |
Date: | 2009-09-10 20:32:58 |
Message-ID: | 1252614778.3931.42.camel@hvost1700 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, 2009-09-10 at 22:15 +0200, Pavel Stehule wrote:
> 2009/9/10 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> > On Thu, 2009-09-10 at 21:35 +0200, Pavel Stehule wrote:
> >> 2009/9/10 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> >> > Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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.
Similar functionality in python allows %s for any type (it will just get
string representation of the value), but not vice-versa:
>>> '%s' % 10
'10'
>>> '%d' % 10
'10'
>>> '%d' % '10'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not str
More restrictive than Tom's proposal.
> 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
this would be interesting for cases like
sprintf('%.2f', '3.1415927')
but I'd frefer here python-like sematics, where you need to make
explicit casts, i.e.
sprintf('%.2f', '3.1415927'::float)
--
Hannu Krosing http://www.2ndQuadrant.com
PostgreSQL Scalability and Availability
Services, Consulting and Training
From | Date | Subject | |
---|---|---|---|
Next Message | Dimitri Fontaine | 2009-09-10 20:33:05 | Re: RfD: more powerful "any" types |
Previous Message | Jan Wieck | 2009-09-10 20:24:15 | Re: Disable and enable of table and column constraints |