NUMERIC x VARCHAR
NUMERIC x VARCHAR
От:
Er Galvão Abbott <galvao@galvao.eti.br>
Дата:
Greetings.
I have a question regarding performance of certain datatypes:
I have a field where I will store my clients phone numbers. I know that this field will never exceed 15 characters, and I will store only numbers here (no dashes, dots, etc...), so I was wondering:
Wich type is faster: NUMERIC(15,0) or VARCHAR(15)? Are there any storage differences between them?
TIA,
-- Er Galvão Abbott Desenvolvedor Web http://www.galvao.eti.br/ galvao@galvao.eti.br
Re: NUMERIC x VARCHAR
От:
"Scott Marlowe" <smarlowe@qwest.net>
Дата:
On Tue, 2004-08-10 at 23:42, Er Galvão Abbott wrote: > Greetings. > > I have a question regarding performance of certain datatypes: > > I have a field where I will store my clients phone numbers. I know > that this field will never exceed 15 characters, and I will store only > numbers here (no dashes, dots, etc...), so I was wondering: > > Wich type is faster: NUMERIC(15,0) or VARCHAR(15)? Are there any > storage differences between them? Since numerics are stored as text strings, the storage would be similar. Numerics, however, may be slower since they have more constraints built in. If you throw a check constraint on the varchar(15) then it will likely be about the same speed for updating. text type with a check contraint it what i'd use. That way if you want to change it at a later date you just drop and recreate your constraint.
Re: NUMERIC x VARCHAR
От:
Pierre-Frédéric Caillaud<lists@boutiquenumerique.com>
Дата:
Numeric won't store that : (+33) 4 01 23 45 67 On Wed, 11 Aug 2004 02:42:33 -0300, Er Galvão Abbott wrote: > Greetings. > > I have a question regarding performance of certain datatypes: > > I have a field where I will store my clients phone numbers. I know that > this > field will never exceed 15 characters, and I will store only numbers > here (no > dashes, dots, etc...), so I was wondering: > > Wich type is faster: NUMERIC(15,0) or VARCHAR(15)? Are there any storage > differences between them? > > TIA, >
Re: NUMERIC x VARCHAR
От:
Er Galvão Abbott <galvao@galvao.eti.br>
Дата:
It will. As I've said I wont be storing any symbols.
-- Er Galvão Abbott Desenvolvedor Web http://www.galvao.eti.br/ galvao@galvao.eti.br
Pierre-Frédéric Caillaud wrote:
Numeric won't store that :
(+33) 4 01 23 45 67
On Wed, 11 Aug 2004 02:42:33 -0300, Er Galvão Abbott <galvao@galvao.eti.br> wrote:Greetings.
I have a question regarding performance of certain datatypes:
I have a field where I will store my clients phone numbers. I know that this
field will never exceed 15 characters, and I will store only numbers here (no
dashes, dots, etc...), so I was wondering:
Wich type is faster: NUMERIC(15,0) or VARCHAR(15)? Are there any storage
differences between them?
TIA,
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Re: NUMERIC x VARCHAR
От:
Michael Glaesemann <grzm@myrealbox.com>
Дата:
On Aug 11, 2004, at 4:27 PM, Er Galvão Abbott wrote:
> It will. As I've said I wont be storing any symbols.
It won't store leading zeros, however. This may or may not be an issue
for you.
test=# create table tel (name_id integer not null, tel_numeric
numeric(15) not null, tel_varchar varchar(15) not null);
CREATE TABLE
test=# insert into tel (name_id, tel_numeric, tel_varchar) values
(1,012345678911234, '012345678911234');
INSERT 17153 1
test=# select * from tel;
name_id | tel_numeric | tel_varchar
---------+----------------+-----------------
1 | 12345678911234 | 012345678911234
(1 row)
I would do as another poster suggested: create a telephone number
domain as text with the check constraints you desire.
Michael Glaesemann
grzm myrealbox com
Re: NUMERIC x VARCHAR
От:
Er Galvão Abbott <galvao@galvao.eti.br>
Дата:
Thanks, Michael.
You and "Evil Azrael" (lol) got me. Never thought about leading zeros.
Varchar it is!
Thanks a lot,-- Er Galvão Abbott Desenvolvedor Web http://www.galvao.eti.br/ galvao@galvao.eti.br
Michael Glaesemann wrote:
On Aug 11, 2004, at 4:27 PM, Er Galvão Abbott wrote:It will. As I've said I wont be storing any symbols.
It won't store leading zeros, however. This may or may not be an issue for you.
test=# create table tel (name_id integer not null, tel_numeric numeric(15) not null, tel_varchar varchar(15) not null);
CREATE TABLE
test=# insert into tel (name_id, tel_numeric, tel_varchar) values (1,012345678911234, '012345678911234');
INSERT 17153 1
test=# select * from tel;
name_id | tel_numeric | tel_varchar
---------+----------------+-----------------
1 | 12345678911234 | 012345678911234
(1 row)
I would do as another poster suggested: create a telephone number domain as text with the check constraints you desire.
Michael Glaesemann
grzm myrealbox com
Re: NUMERIC x VARCHAR
От:
Jan Wieck <JanWieck@Yahoo.com>
Дата:
On 8/11/2004 2:21 AM, Scott Marlowe wrote: > On Tue, 2004-08-10 at 23:42, Er Galvão Abbott wrote: >> Greetings. >> >> I have a question regarding performance of certain datatypes: >> >> I have a field where I will store my clients phone numbers. I know >> that this field will never exceed 15 characters, and I will store only >> numbers here (no dashes, dots, etc...), so I was wondering: >> >> Wich type is faster: NUMERIC(15,0) or VARCHAR(15)? Are there any >> storage differences between them? > > Since numerics are stored as text strings, the storage would be > similar. Numerics, however, may be slower since they have more > constraints built in. If you throw a check constraint on the > varchar(15) then it will likely be about the same speed for updating. They are stored as an array of signed small integers holding digits in base-10000, plus a precision, scale and sign. That's somewhat different from text strings, isn't it? Jan > > text type with a check contraint it what i'd use. That way if you want > to change it at a later date you just drop and recreate your constraint. > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #