Re: [HACKERS] Re: varchar() troubles (fwd)

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: vadim(at)sable(dot)krasnoyarsk(dot)su (Vadim B(dot) Mikheev)
Cc: lockhart(at)alumni(dot)caltech(dot)edu, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: varchar() troubles (fwd)
Date: 1998-01-16 22:48:24
Message-ID: 199801162248.RAA27537@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> Bruce Momjian wrote:
> >
> > > >
> > > > Can I add an 'attdeflen' for "attributed defined length" field to
> > > > pg_attribute, and change the attlen references needed to the new field?
> > > > This is the only proper way to fix it.
> > >
> > > Bruce, does your "temporary fix" seem to repair all known problems with varchar()? If so, would you be interested in
> > > holding off on a "proper fix" and coming back to it after v6.3 is released? At that time, we can try solving the general
> > > problem of retaining column-specific attributes, such as your max len for varchar, declared dimensions for arrays, and
> > > numeric() and decimal() types. Or, if you have time to try a solution now _and_ come back to it later...
> > >
> >
> > In fact, I am inclined to leave attlen unchanged, and add atttyplen that
> > is a copy of the length of the type. That way, the attlen for varchar()
> > really contains the defined length, and atttyplen is used for disk
> > references, and it is very clear what it means.
>
> pg_attribute.h:
>
> int2 attlen;
>
> /*
> * attlen is a copy of the typlen field from pg_type for this
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> * attribute...
> ^^^^^^^^^
> : I would suggest to don't change this to preserve the same meaning
> for all data types. attlen = -1 means that attribute is varlena.
>
> We certainly need in new field in pg_attribute! I don't like names like
> "attdeflen" or "atttyplen" - bad names for NUMERIC etc. Something like
> atttspec (ATTribute Type SPECification) is better, imho.
>
> For the varchar(N) we'll have attlen = -1 and atttspec = N (or N + 4 - what's
> better). For the text: attlen = -1 and atttspec = -1. And so on.
>
> Of 'course, it's not so much matter where to put maxlen of varchar.
> attlen = -1 for varchar just seems more clear to me.
>
> But in any case we need in new field and, imho, this should be added
> in 6.3

OK, we have a new pg_attribute column called 'atttypmod' for
'type-specific modifier'. Currently, it is only used to hold the char
and varchar length, but I am sure will be used soon for other types.

Here is the test:

test=> insert into test values ('asdfasdfasdfasdfasdfadsfasdf11',3);
INSERT 18282 1
test=> select * from test;
x |y
--------------------+-
asdfasdfasdfasdfasdf|3
(1 row)

'attlen' was certainly a confusing double-used field that I am glad to
return to single-use status.

I will be installing the patch soon, and will then start on subselects
in the parser. It will probably take me until Monday to finish that.

--
Bruce Momjian
maillist(at)candle(dot)pha(dot)pa(dot)us

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brian Sanders 1998-01-17 00:39:49 testlibpq3 gives incorrect results
Previous Message Bruce Momjian 1998-01-16 21:35:49 Re: [HACKERS] Latest src tree