pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Field length ??
7+ messages / 4 participants
[nested] [flat]

* Field length ??
@ 2006-04-20 03:32 Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 06:08 ` Re: Field length ?? Louise Catherine <r1c4n@yahoo.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Louise Catherine @ 2006-04-20 03:32 UTC (permalink / raw)
  To: pgsql-sql

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.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Field length ??
  2006-04-20 03:32 Field length ?? Louise Catherine <r1c4n@yahoo.com>
@ 2006-04-20 06:08 ` Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 09:16   ` Re: Field length ?? Markus Schaber <schabi@logix-tt.com>
  2006-04-20 15:21   ` Re: Field length ?? Frank Bax <fbax@sympatico.ca>
  0 siblings, 2 replies; 7+ messages in thread

From: Louise Catherine @ 2006-04-20 06:08 UTC (permalink / raw)
  To: pgsql-sql

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! Messenger’s low  PC-to-Phone call rates.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Field length ??
  2006-04-20 03:32 Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 06:08 ` Re: Field length ?? Louise Catherine <r1c4n@yahoo.com>
@ 2006-04-20 09:16   ` Markus Schaber <schabi@logix-tt.com>
  2006-04-20 14:27     ` Re: Field length ?? Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 7+ messages in thread

From: Markus Schaber @ 2006-04-20 09:16 UTC (permalink / raw)
  To: Louise Catherine <r1c4n@yahoo.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Field length ??
  2006-04-20 03:32 Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 06:08 ` Re: Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 09:16   ` Re: Field length ?? Markus Schaber <schabi@logix-tt.com>
@ 2006-04-20 14:27     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2006-04-20 14:27 UTC (permalink / raw)
  To: Markus Schaber <schabi@logix-tt.com>; +Cc: Louise Catherine <r1c4n@yahoo.com>; pgsql-sql

Markus Schaber <schabi@logix-tt.com> 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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Field length ??
  2006-04-20 03:32 Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 06:08 ` Re: Field length ?? Louise Catherine <r1c4n@yahoo.com>
@ 2006-04-20 15:21   ` Frank Bax <fbax@sympatico.ca>
  2006-04-20 15:36     ` Re: Field length ?? Markus Schaber <schabi@logix-tt.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Frank Bax @ 2006-04-20 15:21 UTC (permalink / raw)
  To: pgsql-sql

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)
         );





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Field length ??
  2006-04-20 03:32 Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 06:08 ` Re: Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 15:21   ` Re: Field length ?? Frank Bax <fbax@sympatico.ca>
@ 2006-04-20 15:36     ` Markus Schaber <schabi@logix-tt.com>
  2006-04-20 15:44       ` Re: Field length ?? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Markus Schaber @ 2006-04-20 15:36 UTC (permalink / raw)
  To: Frank Bax <fbax@sympatico.ca>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Field length ??
  2006-04-20 03:32 Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 06:08 ` Re: Field length ?? Louise Catherine <r1c4n@yahoo.com>
  2006-04-20 15:21   ` Re: Field length ?? Frank Bax <fbax@sympatico.ca>
  2006-04-20 15:36     ` Re: Field length ?? Markus Schaber <schabi@logix-tt.com>
@ 2006-04-20 15:44       ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2006-04-20 15:44 UTC (permalink / raw)
  To: Markus Schaber <schabi@logix-tt.com>; +Cc: Frank Bax <fbax@sympatico.ca>; pgsql-sql

Markus Schaber <schabi@logix-tt.com> 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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2006-04-20 15:44 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-04-20 03:32 Field length ?? Louise Catherine <r1c4n@yahoo.com>
2006-04-20 06:08 ` Louise Catherine <r1c4n@yahoo.com>
2006-04-20 09:16   ` Markus Schaber <schabi@logix-tt.com>
2006-04-20 14:27     ` Tom Lane <tgl@sss.pgh.pa.us>
2006-04-20 15:21   ` Frank Bax <fbax@sympatico.ca>
2006-04-20 15:36     ` Markus Schaber <schabi@logix-tt.com>
2006-04-20 15:44       ` 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