Thread: upcasting multiplication in a query

upcasting multiplication in a query

From
"John Guthrie"
Date:
i have a schema that stores timestamps in seconds/microseconds format. each
column in the table is int4. what i want to do is to compute the int8 value
of total microseconds, a la: select (seconds*1000000)+micros from my_table;
but it looks to me like postgresql puts the rresult into another int4 (since
i am getting negative numbers, i assume overflow). how can i get it to use
int8?

thanks.
---
john guthrie
jguthrie@psynapsetech.net




Re: upcasting multiplication in a query

From
dev@archonet.com
Date:
> i have a schema that stores timestamps in seconds/microseconds format.
> each
> column in the table is int4. what i want to do is to compute the int8
> value
> of total microseconds, a la:
>   select (seconds*1000000)+micros from my_table;
> but it looks to me like postgresql puts the rresult into another int4
> (since
> i am getting negative numbers, i assume overflow). how can i get it to use
> int8?

Try (seconds::int8 * 10000000)+micros - you could use cast(...) if you
want to be more standard.

- Richard Huxton


Re: upcasting multiplication in a query

From
Tom Lane
Date:
"John Guthrie" <jguthrie@psynapsetech.net> writes:
>   select (seconds*1000000)+micros from my_table;
> but it looks to me like postgresql puts the rresult into another int4 (since
> i am getting negative numbers, i assume overflow). how can i get it to use
> int8?

Cast the constant to int8.
        regards, tom lane