pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCasting
6+ messages / 6 participants
[nested] [flat]
* Casting
@ 2001-01-05 00:31 Thomas SMETS <tsmets@altern.org>
2001-01-05 13:24 ` Re: Casting rob <rob@cabrion.com>
2001-01-05 18:42 ` Re: [SQL] Casting Peter Eisentraut <peter_e@gmx.net>
0 siblings, 2 replies; 6+ messages in thread
From: Thomas SMETS @ 2001-01-05 00:31 UTC (permalink / raw)
To: psql novice <pgsql-novice@postgresql.org>; pgsql-sql
Hi,
In pgsql
I'm removing charaters from a String which should be numbers.
I then want to make calculations on these numbers (calculate the ISBN
number).
Do I have to cast the char into int's before I can do the calulations.
Also I looked in the User manual but could not find the modulo function
where is it ?
tx,
Thomas,
--
Thu Jan 4 20:19:03 CET 2001
Thomas SMETS e-mail : tsmets@altern.org
Av. de la Brabançonne 133 / 3 Tel. : +32 (0)2 742. 05. 94.
1030 Bruxelles
======= Quote of the Day =========
Jealousy is all the fun you think they have.
========= End of Quote ===========
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Casting
2001-01-05 00:31 Casting Thomas SMETS <tsmets@altern.org>
@ 2001-01-05 13:24 ` rob <rob@cabrion.com>
1 sibling, 0 replies; 6+ messages in thread
From: rob @ 2001-01-05 13:24 UTC (permalink / raw)
To: Thomas SMETS <tsmets@altern.org>; psql novice <pgsql-novice@postgresql.org>; pgsql-sql
Yes. Casts are done like this:
SomeFiled::int4
or SomeField::text
Double colons is the key '::'
--rob
----- Original Message -----
From: "Thomas SMETS" <tsmets@altern.org>
To: "psql novice" <pgsql-novice@postgresql.org>; "psql sql"
<pgsql-sql@postgresql.org>
Sent: Thursday, January 04, 2001 7:31 PM
Subject: Casting
>
>
> Hi,
>
> In pgsql
>
> I'm removing charaters from a String which should be numbers.
> I then want to make calculations on these numbers (calculate the ISBN
> number).
>
> Do I have to cast the char into int's before I can do the calulations.
>
> Also I looked in the User manual but could not find the modulo function
> where is it ?
>
> tx,
>
> Thomas,
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> Thu Jan 4 20:19:03 CET 2001
>
> Thomas SMETS e-mail : tsmets@altern.org
> Av. de la Brabançonne 133 / 3 Tel. : +32 (0)2 742. 05. 94.
> 1030 Bruxelles
> ======= Quote of the Day =========
> Jealousy is all the fun you think they have.
> ========= End of Quote ===========
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [SQL] Casting
2001-01-05 00:31 Casting Thomas SMETS <tsmets@altern.org>
@ 2001-01-05 18:42 ` Peter Eisentraut <peter_e@gmx.net>
1 sibling, 0 replies; 6+ messages in thread
From: Peter Eisentraut @ 2001-01-05 18:42 UTC (permalink / raw)
To: Thomas SMETS <tsmets@altern.org>; +Cc: psql novice <pgsql-novice@postgresql.org>; pgsql-sql
Thomas SMETS writes:
> I'm removing charaters from a String which should be numbers.
> I then want to make calculations on these numbers (calculate the ISBN
> number).
(You might want to look into contrib/isbn_issn for an isbn type.)
> Do I have to cast the char into int's before I can do the calulations.
Depends on the calculation. I'd just try to see if it works. When in
doubt add casts.
> Also I looked in the User manual but could not find the modulo function
> where is it ?
5 % 4
mod(5, 4)
--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/
^ permalink raw reply [nested|flat] 6+ messages in thread
* Casting
@ 2002-03-13 17:41 Graham Vickrage <graham@digitalplanit.com>
2002-03-13 20:25 ` Re: Casting PG Explorer <pgmail@pgexplorer.com>
2002-03-13 22:10 ` Re: Casting Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 6+ messages in thread
From: Graham Vickrage @ 2002-03-13 17:41 UTC (permalink / raw)
To: pgsql-sql
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.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Casting
2002-03-13 17:41 Casting Graham Vickrage <graham@digitalplanit.com>
@ 2002-03-13 20:25 ` PG Explorer <pgmail@pgexplorer.com>
1 sibling, 0 replies; 6+ messages in thread
From: PG Explorer @ 2002-03-13 20:25 UTC (permalink / raw)
To: Graham Vickrage <graham@digitalplanit.com>; pgsql-sql
Try
to_char(numeric, text)
to_char('125', '9999999999D')
http://www.pgexplorer.com
Postgres GUI
----- Original Message -----
From: "Graham Vickrage" <graham@digitalplanit.com>
To: "Postgres SQL" <pgsql-sql@postgresql.org>
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Casting
2002-03-13 17:41 Casting Graham Vickrage <graham@digitalplanit.com>
@ 2002-03-13 22:10 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 6+ messages in thread
From: Tom Lane @ 2002-03-13 22:10 UTC (permalink / raw)
To: Graham Vickrage <graham@digitalplanit.com>; +Cc: pgsql-sql
"Graham Vickrage" <graham@digitalplanit.com> 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
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2002-03-13 22:10 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-01-05 00:31 Casting Thomas SMETS <tsmets@altern.org>
2001-01-05 13:24 ` rob <rob@cabrion.com>
2001-01-05 18:42 ` Peter Eisentraut <peter_e@gmx.net>
2002-03-13 17:41 Casting Graham Vickrage <graham@digitalplanit.com>
2002-03-13 20:25 ` PG Explorer <pgmail@pgexplorer.com>
2002-03-13 22:10 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox