Re: Changing Data Types

Поиск
Список
Период
Сортировка
От Mike Frost
Тема Re: Changing Data Types
Дата
Msg-id DUB127-W93405B915C0FA12BA7E94E82540@phx.gbl
обсуждение исходный текст
Ответ на Re: Changing Data Types  (Thom Brown <thom@linux.com>)
Ответы Re: Changing Data Types  (James David Smith <james.david.smith@gmail.com>)
Re: Changing Data Types  (Thom Brown <thom@linux.com>)
Список pgsql-novice
thanks man!

so the syntax in [fielname]::[datatype]?


From: thom@linux.com
Date: Mon, 7 Sep 2015 11:27:46 +0100
Subject: Re: [NOVICE] Changing Data Types
To: m_frost2010@hotmail.com
CC: tgl@sss.pgh.pa.us; pgsql-novice@postgresql.org

On 7 September 2015 at 11:20, Mike Frost <m_frost2010@hotmail.com> wrote:
Hi All,

This REALLY is a novice question

I'm writing a simple query where i need to return [Field A]/[Field B] so i can express [Field A] as a percentage

Both of these fields are BigInts, so i always get 0

What do i need to do to the data types in my query to enable decimal places?

You can cast at least one of them to numeric:

postgres=# SELECT 7::int / 10::int;
 ?column?
----------
        0
(1 row)

postgres=# SELECT 7::numeric / 10::int;
        ?column?       
------------------------
 0.70000000000000000000
(1 row)

Thom

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

Предыдущее
От: Thom Brown
Дата:
Сообщение: Re: Changing Data Types
Следующее
От: James David Smith
Дата:
Сообщение: Re: Changing Data Types