attlen weirdness?

Поиск
Список
Период
Сортировка
Искать

attlen weirdness?

От:
"Julia 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	

Calendar Created

! \. 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. ]

Re: [HACKERS] attlen weirdness?

От:
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 :(

Thanks...

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

> 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	

Calendar Created

! > ! > ! > > \. > 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. ] >

Re: [HACKERS] attlen weirdness?

От:
"Julia A.Case" <julie@hub.org>
Дата:
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. ]

Re: [HACKERS] attlen weirdness?

От:
Bruce Momjian <maillist@candle.pha.pa.us>
Дата:
> 
> 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)

Re: [HACKERS] attlen weirdness?

От:
Bruce Momjian <maillist@candle.pha.pa.us>
Дата:
> 
> 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)

Re: [HACKERS] attlen weirdness?

От:
"Julia A.Case" <julie@hub.org>
Дата:
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. ]

Re: [HACKERS] attlen weirdness?

От:
Bruce Momjian <maillist@candle.pha.pa.us>
Дата:
> 
> 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)

Re: [HACKERS] attlen weirdness?

От:
"Julia A.Case" <julie@hub.org>
Дата:
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. ]

Re: [HACKERS] attlen weirdness?

От:
Bruce Momjian <maillist@candle.pha.pa.us>
Дата:
> 
> 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)
FAQ