attlen weirdness?

Started by Julia A.Casealmost 28 years ago13 messages
#1Julia A.Case
julie@hub.org

I am using the following info to migrate a table from 6.2.1 to 6.3

\connect template1
drop database magecal;
create database magecal;
\connect magecal
\connect - julie
CREATE TABLE dates (id int4, date char(10), news char(1024)) archive = none;
COPY dates FROM stdin;
1 1998Jan16 <H3>Calendar Created</H3> !

\.
CREATE INDEX dates_indx on dates using btree ( id int4_ops, date bpchar_ops );

now if I connect to the database and do

select attlen from pg_attribute where attname='news';

I get
-1

This doesn't seem quite right.

Julie

--
[ Julia Anne Case ] [ Ships are safe inside the harbor, ]
[Programmer at large] [ but is that what ships are really for. ]
[ Admining Linux ] [ To thine own self be true. ]
[ Windows/WindowsNT ] [ Fair is where you take your cows to be judged. ]

#2Julia A.Case
julie@hub.org
In reply to: Julia A.Case (#1)
Re: [HACKERS] attlen weirdness?

Quoting The Hermit Hacker (scrappy@hub.org):

Bruce? Guys? Any word on this one? I *thought* I remembered reading
soething about the 'attlen' becoming -1, but just checked the mailing list
archives and couldn't find anything :(

It appears as if atttypmod now has the field length + 4 ???

Julie

--
[ Julia Anne Case ] [ Ships are safe inside the harbor, ]
[Programmer at large] [ but is that what ships are really for. ]
[ Admining Linux ] [ To thine own self be true. ]
[ Windows/WindowsNT ] [ Fair is where you take your cows to be judged. ]

#3Julia A.Case
julie@hub.org
In reply to: Julia A.Case (#2)
Re: [HACKERS] attlen weirdness?

Quoting Bruce Momjian (maillist@candle.pha.pa.us):

I assume you are asking of attlen for char() and varchar() have the max
length. The answer is now NO. They are varlena structures like text,
and so have a attlen of -1. Atttypmod for that pg_attribute row now has
the defined length.

Even for a char(4) field? ok, if attlen doesn't give the
length of a field, how do I find it?

Julie

--
[ Julia Anne Case ] [ Ships are safe inside the harbor, ]
[Programmer at large] [ but is that what ships are really for. ]
[ Admining Linux ] [ To thine own self be true. ]
[ Windows/WindowsNT ] [ Fair is where you take your cows to be judged. ]

#4Julia A.Case
julie@hub.org
In reply to: Julia A.Case (#3)
Re: [HACKERS] attlen weirdness?

Quoting Bruce Momjian (maillist@candle.pha.pa.us):

pg_attribute.atttypmod.

this field appears to be field size + 4
in a char(1024) field it returns 1028
in a char(10) it returns 14

is it padded?

Julie

--
[ Julia Anne Case ] [ Ships are safe inside the harbor, ]
[Programmer at large] [ but is that what ships are really for. ]
[ Admining Linux ] [ To thine own self be true. ]
[ Windows/WindowsNT ] [ Fair is where you take your cows to be judged. ]

#5The Hermit Hacker
scrappy@hub.org
In reply to: Julia A.Case (#1)
Re: [HACKERS] attlen weirdness?

Bruce? Guys? Any word on this one? I *thought* I remembered reading
soething about the 'attlen' becoming -1, but just checked the mailing list
archives and couldn't find anything :(

Thanks...

On Tue, 10 Mar 1998, Julia A.Case wrote:

Show quoted text

I am using the following info to migrate a table from 6.2.1 to 6.3

\connect template1
drop database magecal;
create database magecal;
\connect magecal
\connect - julie
CREATE TABLE dates (id int4, date char(10), news char(1024)) archive = none;
COPY dates FROM stdin;
1 1998Jan16 <H3>Calendar Created</H3> !
!
!

\.
CREATE INDEX dates_indx on dates using btree ( id int4_ops, date bpchar_ops );

now if I connect to the database and do

select attlen from pg_attribute where attname='news';

I get
-1

This doesn't seem quite right.

Julie

--
[ Julia Anne Case ] [ Ships are safe inside the harbor, ]
[Programmer at large] [ but is that what ships are really for. ]
[ Admining Linux ] [ To thine own self be true. ]
[ Windows/WindowsNT ] [ Fair is where you take your cows to be judged. ]

#6Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Julia A.Case (#2)
Re: [HACKERS] attlen weirdness?

Quoting The Hermit Hacker (scrappy@hub.org):

Bruce? Guys? Any word on this one? I *thought* I remembered reading
soething about the 'attlen' becoming -1, but just checked the mailing list
archives and couldn't find anything :(

It appears as if atttypmod now has the field length + 4 ???

I am the atttypmod guy, but there is not enough context to answer this
question.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)
#7Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Julia A.Case (#2)
Re: [HACKERS] attlen weirdness?

Quoting The Hermit Hacker (scrappy@hub.org):

Bruce? Guys? Any word on this one? I *thought* I remembered reading
soething about the 'attlen' becoming -1, but just checked the mailing list
archives and couldn't find anything :(

It appears as if atttypmod now has the field length + 4 ???

I assume you are asking of attlen for char() and varchar() have the max
length. The answer is now NO. They are varlena structures like text,
and so have a attlen of -1. Atttypmod for that pg_attribute row now has
the defined length.

In the old days, pre 6.3, pg_type.typlen != pg_attribute.attlen for
char() and varchar(), causing all sorts of type-conditional wierness in
the backend for these types. With the new code, pg_type.typlen =
pg_attribute.attlen all the time.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)
#8Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Julia A.Case (#3)
Re: [HACKERS] attlen weirdness?

Quoting Bruce Momjian (maillist@candle.pha.pa.us):

I assume you are asking of attlen for char() and varchar() have the max
length. The answer is now NO. They are varlena structures like text,
and so have a attlen of -1. Atttypmod for that pg_attribute row now has
the defined length.

Even for a char(4) field? ok, if attlen doesn't give the
length of a field, how do I find it?

pg_attribute.atttypmod.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)
#9Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Julia A.Case (#4)
Re: [HACKERS] attlen weirdness?

Quoting Bruce Momjian (maillist@candle.pha.pa.us):

pg_attribute.atttypmod.

this field appears to be field size + 4
in a char(1024) field it returns 1028
in a char(10) it returns 14

is it padded?

Yes. All varlena sizes store the VARHDRSZ, variable header size of 4,
in the length field.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)
#10Zeugswetter Andreas
andreas.zeugswetter@telecom.at
In reply to: Bruce Momjian (#8)
AW: [HACKERS] attlen weirdness?

Quoting Bruce Momjian (maillist@candle.pha.pa.us):

I assume you are asking of attlen for char() and varchar() have the max
length. The answer is now NO. They are varlena structures like text,
and so have a attlen of -1. Atttypmod for that pg_attribute row now has
the defined length.

Even for a char(4) field? ok, if attlen doesn't give the
length of a field, how do I find it?

Right now: yes, but I would like to see the char() type changed to a fixed length type (which it really is)
then it would have the length in attlen. Right now the length for char and varchar is in atttypmod.

Andreas

#11Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Zeugswetter Andreas (#10)
Re: AW: [HACKERS] attlen weirdness?

Quoting Bruce Momjian (maillist@candle.pha.pa.us):

I assume you are asking of attlen for char() and varchar() have the max
length. The answer is now NO. They are varlena structures like text,
and so have a attlen of -1. Atttypmod for that pg_attribute row now has
the defined length.

Even for a char(4) field? ok, if attlen doesn't give the
length of a field, how do I find it?

Right now: yes, but I would like to see the char() type changed to a fixed length type (which it really is)
then it would have the length in attlen. Right now the length for char and varchar is in atttypmod.

Again, we can do this, but we then have to have atttypmod available in
all places where we check for length. I will add it to the TODO list.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)
#12Zeugswetter Andreas
andreas.zeugswetter@telecom.at
In reply to: Bruce Momjian (#11)
AW: AW: [HACKERS] attlen weirdness?

Right now: yes, but I would like to see the char() type changed to a fixed length type (which it really is)
then it would have the length in attlen. Right now the length for char and varchar is in atttypmod.

Again, we can do this, but we then have to have atttypmod available in
all places where we check for length. I will add it to the TODO list.

I am starting to see the problem, only atttypmod is passed around not attlen.
Therefore even if we do this, the char() length of a column still has to be in atttypmod.
So it will stay the same for Julie, whether it is taken out or not. But since it is really
hard for a generic application like ODBC, maybe we could change atttypmod to not
include the VARHDRSZ, most of the time it is needed without VARHDRSZ anyway ?
I am starting to think that this would be more important than to remove the 4 bytes.

Andreas

#13Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Zeugswetter Andreas (#12)
Re: AW: AW: [HACKERS] attlen weirdness?

Right now: yes, but I would like to see the char() type changed to a fixed length type (which it really is)
then it would have the length in attlen. Right now the length for char and varchar is in atttypmod.

Again, we can do this, but we then have to have atttypmod available in
all places where we check for length. I will add it to the TODO list.

I am starting to see the problem, only atttypmod is passed around not attlen.
Therefore even if we do this, the char() length of a column still has to be in atttypmod.
So it will stay the same for Julie, whether it is taken out or not. But since it is really
hard for a generic application like ODBC, maybe we could change atttypmod to not
include the VARHDRSZ, most of the time it is needed without VARHDRSZ anyway ?
I am starting to think that this would be more important than to remove the 4 bytes.

Those four bytes have always been there. Check psql or pg_dump. See
them subtracting VARHDRSZ all the time.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)