Field length ??
Field length ??
От:
Louise Catherine <r1c4n@yahoo.com>
Дата:
I've this table :
create table test(]
satu char(10),
dua char(5)
);
How could I get the Field length not the Data length ?
Thanks,
Rina
Love cheap thrills? Enjoy PC-to-Phone calls to 30+ countries for just 2¢/min with Yahoo! Messenger with Voice.
Re: Field length ??
От:
Louise Catherine <r1c4n@yahoo.com>
Дата:
Hi ,
With this table :
create table test(
satu char(10),
dua char(5)
);
To get the field length, I use this query:
select atttypmod from pg_attribute where
attname='satu' and
attrelid=(select oid from pg_class where relname='test');
---> result 1 : 14
select atttypmod from pg_attribute where
attname='dua' and
attrelid=(select oid from pg_class where relname='test');
---> result 2 : 9
Could anyone explain, why the field length must be add by 4 :
result 1 : 10 + 4 =14
result 2 : 5 + 4 = 9
Could I use this query ? Is it valid?
select atttypmod-4 from pg_attribute where
attname='satu' and
attrelid=(select oid from pg_class where relname='test');
Thank's,
Rina
How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.
Re: Field length ??
От:
Markus Schaber <schabi@logix-tt.com>
Дата:
Hi, Louise, Louise Catherine wrote: > Could anyone explain, why the field length must be add by 4 : > result 1 : 10 + 4 =14 > result 2 : 5 + 4 = 9 I guess that it is because all variable length datatypes (and text types are such) internally contain a 4 bytes length field. http://www.postgresql.org/docs/8.1/interactive/xtypes.html might be a start if you want to read more on this topic. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org
Re: Field length ??
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Markus Schaber writes: > Louise Catherine wrote: >> Could anyone explain, why the field length must be add by 4 : > I guess that it is because all variable length datatypes (and text types > are such) internally contain a 4 bytes length field. It's an ancient decision that no longer has much of anything to do with reality, but changing it would break more code than it's worth to have a slightly cleaner definition of atttypmod ... regards, tom lane
Re: Field length ??
От:
Frank Bax <fbax@sympatico.ca>
Дата:
At 05:16 AM 4/20/06, Markus Schaber wrote: >Hi, Louise, > >Louise Catherine wrote: > > > Could anyone explain, why the field length must be add by 4 : > > result 1 : 10 + 4 =14 > > result 2 : 5 + 4 = 9 > >I guess that it is because all variable length datatypes (and text types >are such) internally contain a 4 bytes length field. Except that the original fields were neither variable length datatypes, not type text. create table test(] satu char(10), dua char(5) );
Re: Field length ??
От:
Markus Schaber <schabi@logix-tt.com>
Дата:
Hi, Frank, Frank Bax wrote: > Except that the original fields were neither variable length datatypes, > not type text. > create table test(] > satu char(10), > dua char(5) > ); char is a textual type (in opposite to numeric types), and they are handled as variable length datatypes internally (even if given a limit). See http://www.postgresql.org/docs/8.1/static/datatype-character.html HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org
Re: Field length ??
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Markus Schaber writes: > Frank Bax wrote: >> Except that the original fields were neither variable length datatypes, >> not type text. > char is a textual type (in opposite to numeric types), and they are > handled as variable length datatypes internally (even if given a limit). char(n) *is* a variable-length type, not merely "handled as such", because the limit N is measured in characters not bytes. To support variable-length encodings such as UTF8 we have to treat it as variable length. regards, tom lane