Re: Should casting to integer produce same result as trunc()

Поиск
Список
Период
Сортировка
От Harvey, Allan AC
Тема Re: Should casting to integer produce same result as trunc()
Дата
Msg-id E97A5BB7699CAD48BE2711E712471165073F8F49@ntlmsg03.onesteel.com
обсуждение исходный текст
Ответ на Re: Should casting to integer produce same result as trunc()  (Alban Hertroys <haramrae@gmail.com>)
Список pgsql-general
> -----Original Message-----
> From: Alban Hertroys [mailto:haramrae@gmail.com]
> Sent: Wednesday, 12 October 2011 1:35 AM
> To: Tom Lane
> Cc: Harvey, Allan AC; pgsql-general@postgresql.org
> Subject: Re: [GENERAL] Should casting to integer produce same
> result as trunc()
>
> On 11 October 2011 15:41, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > Alban Hertroys <haramrae@gmail.com> writes:
> >> On 11 Oct 2011, at 2:55, Harvey, Allan AC wrote:
> >>> My simple understanding of trunc() and casting to an
> integer says that
> >>> there is a bug here.
> >
> >> Which the type-cast should round to 4380103 and 4380104
> respectively.
> >> It doesn't:
> >
> > That's because a cast from float to int rounds, it doesn't truncate.
> >
> > regression=# select (4.7::float8)::int;
> >  int4
> > ------
> >    5
> > (1 row)
>
> I figured it would be something like that. Is that how it's defined in
> the SQL standard?
>
> All other programming languages I've come to know truncate floats on
> such casts (C, php, python, java, to name a few).
> This is probably quite surprising to people used to these languages.

Thanks guys, yes C/C++ is my poison, forming my expectations.

Allan


The material contained in this email may be confidential, privileged or copyrighted. If you are not the intended
recipient,use, disclosure or copying of this information is prohibited. If you have received this document in error,
pleaseadvise the sender and delete the document. Neither OneSteel nor the sender accept responsibility for any viruses
containedin this email or any attachments. 

В списке pgsql-general по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: libpq 8.3 and 8.4 interfaces
Следующее
От: Joe Abbate
Дата:
Сообщение: Re: how to save primary key constraints