Casting

Поиск
Список
Период
Сортировка
Искать

Casting

От:
"Graham Vickrage" <graham@digitalplanit.com>
Дата:
Hi All,

Probably a very simple question, but... I am trying to cast a large number
approx
20 chars into text so I can manipulate it. I have tried

SELECT text(big_number) from table;

but this comes back in the format 3.2304234234233e+15 for example, whis is
no good. I essentially need the last four digits of the number (securing
credit card numbers is the idea), which I can only do by manipulating text
and casting it back.

Does anyone have any suggestions?

Many thanks,

Graham.



Re: Casting

От:
"PG Explorer" <pgmail@pgexplorer.com>
Дата:
Try
to_char(numeric, text)
to_char('125', '9999999999D')

http://www.pgexplorer.com
Postgres GUI


----- Original Message -----
From: "Graham Vickrage" 
To: "Postgres SQL" 
Sent: Wednesday, March 13, 2002 7:41 PM
Subject: [SQL] Casting


> Hi All,
>
> Probably a very simple question, but... I am trying to cast a large number
> approx
> 20 chars into text so I can manipulate it. I have tried
>
> SELECT text(big_number) from table;
>
> but this comes back in the format 3.2304234234233e+15 for example, whis is
> no good. I essentially need the last four digits of the number (securing
> credit card numbers is the idea), which I can only do by manipulating text
> and casting it back.
>
> Does anyone have any suggestions?
>
> Many thanks,
>
> Graham.
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


Re: Casting

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Graham Vickrage"  writes:
> I essentially need the last four digits of the number (securing
> credit card numbers is the idea), which I can only do by manipulating text
> and casting it back.

What's wrong with a modulo operation?

regression=# select '123456789'::int8 % 10000::int8;?column? 
----------    6789
(1 row)
		regards, tom lane

FAQ