[BUGS] Need some help: attlen is pg_attributes gives a negative value...

2000-05-03 Thread Klein, Robert

I have a table defined as:

create table contacts (
   c_name   char (20),
   c_title  char (30),
   c_phone  char (13),
   c_extchar (5),
   c_email  char (60),
   c_sort   char (5)
);

when I query the catalog to get the field length for auto generating HTML
forms I get:

attnum|attname|typname|attlen
--+---+---+--
 1|c_name |bpchar |-1
 2|c_title|bpchar |-1
 3|c_phone|bpchar |-1
 4|c_ext  |bpchar |-1
 5|c_email|bpchar |-1
 6|c_sort |bpchar |-1
(6 rows)


I know in previous versions the length as defined in the create table
statement was given.  Any ideas?

Rob



RE: [BUGS] Need some help: attlen is pg_attributes gives a negative value.. .

2000-05-03 Thread Klein, Robert

I just answered my own question.  atttypmod now holds this value.

thanks,
Rob

-Original Message-
From: Klein, Robert [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 03, 2000 4:27 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: [BUGS] Need some help: attlen is pg_attributes gives a negative
value.. .


I have a table defined as:

create table contacts (
   c_name   char (20),
   c_title  char (30),
   c_phone  char (13),
   c_extchar (5),
   c_email  char (60),
   c_sort   char (5)
);

when I query the catalog to get the field length for auto generating HTML
forms I get:

attnum|attname|typname|attlen
--+---+---+--
 1|c_name |bpchar |-1
 2|c_title|bpchar |-1
 3|c_phone|bpchar |-1
 4|c_ext  |bpchar |-1
 5|c_email|bpchar |-1
 6|c_sort |bpchar |-1
(6 rows)


I know in previous versions the length as defined in the create table
statement was given.  Any ideas?

Rob



Re: [BUGS] Need some help: attlen is pg_attributes gives a negative value.. .

2000-05-03 Thread Tom Lane

"Klein, Robert" <[EMAIL PROTECTED]> writes:
> [ attlen for a char(n) field is -1 ]

> I know in previous versions the length as defined in the create table
> statement was given.  Any ideas?

Must have been quite a few versions back; attlen has been -1 for
variable-length datatypes for as long as I've been paying attention.
(Of course char(n) isn't *really* variable length, but it's treated
that way so that the representation is the same as for varchar(n) and
text.)

atttypmod is what you want for determining the length of char(n) fields.
I believe it's n+4 for a char(n) field.

regards, tom lane



Re: [BUGS] Need some help: attlen is pg_attributes gives a negative value.. .

2000-05-03 Thread Roland Roberts

> "Tom" == Tom Lane <[EMAIL PROTECTED]> writes:

Tom> "Klein, Robert" <[EMAIL PROTECTED]> writes:
>> [ attlen for a char(n) field is -1 ]

>> I know in previous versions the length as defined in the create
>> table statement was given.  Any ideas?

Tom> Must have been quite a few versions back; attlen has been -1
Tom> for variable-length datatypes for as long as I've been paying
Tom> attention. (Of course char(n) isn't *really* variable length,
Tom> but it's treated that way so that the representation is the
Tom> same as for varchar(n) and text.)

When did this change?  I haven't looked 6.5, but I thought 6.3 still
has bpchar as fixed length and char(n) was blank padded whereas
varchar was not.

roland
-- 
   PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhDUnix Software Solutions
[EMAIL PROTECTED]  76-15 113th Street, Apt 3B
[EMAIL PROTECTED]  Forest Hills, NY 11375



Re: [BUGS] Need some help: attlen is pg_attributes gives a negative value.. .

2000-05-03 Thread Tom Lane

Roland Roberts <[EMAIL PROTECTED]> writes:
>> "Tom" == Tom Lane <[EMAIL PROTECTED]> writes:
Tom> Must have been quite a few versions back; attlen has been -1
Tom> for variable-length datatypes for as long as I've been paying
Tom> attention. (Of course char(n) isn't *really* variable length,
Tom> but it's treated that way so that the representation is the
Tom> same as for varchar(n) and text.)

> When did this change?  I haven't looked 6.5, but I thought 6.3 still
> has bpchar as fixed length and char(n) was blank padded whereas
> varchar was not.

char(n) was and is blank-padded, varchar(n) was and is not.  Sorry
if I was imprecise enough to convey a different impression.

I'm fairly sure that attlen had its present semantics in 6.4.  6.3
was before my time; any old-timers care to comment?

regards, tom lane