Re: Adding field length to protocol. - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: Adding field length to protocol.
Date
Msg-id 34E82BF3.B5C15E38@sid.trust.ee
Whole thread Raw
List pgsql-hackers
Edmund Mergl <E.Mergl@bawue.de> wrote:

> Bruce Momjian wrote:
> >
> > >
> > > Hi all,
> > >
> > > I would like to add the following item to the
> > > wishlist:
> > >
> > > currently the libpq-function PQfsize returns the
> > > size in bytes of the field with the given field-
> > > index. If the field is a variable-length field,
> > > PQfsize returns -1.
> > >
> > > In general as well as for some internal functionality
> > > of the perl interface it would be useful, if PQfsize
> > > would return the number of bytes even for variable-
> > > length fields.
> >
> > We have a new atttypmod field that holds the length for the column
as
> > defined at table-creation time for char() and varchar().  Is that
the
> > number you want?

I think this number should be available in protocol as several
front-ends want to know it.

It can of course be read from the column definition tables but that
would mean that the front-end
has to parse the query as well.

We would need to supply reasonable defaults for results of expressions,
meaning that length of a
concatenation of varchar(10) and
varchar(20) should be returned as 30 but if it is currently undoable it
could be returned as -1
(variable) for now.

> for varchar() and also for the datatype text it would be
> nice to know the actual length. If this is not possible,
> then the length at creation time is still better than -1.
>
The actual length is given in each data tuple and can be different for
each tuple.

What would be interesting is maximum length (for example the PostODBC
does weird things (it
executes the query and measures each string
:) to determine this, and last time I checked did it in a way that could
break delphi as different
where clause got different lengths)

I suggested a hack to fix it (at the time of v6.1), that would open a
binary cursor (as these are
zero padded to max length) and read
only enough records to get a non-null record for each variable field,
but I'm not sure it got
implemented as I lost interest in ODBC
soon after it.

I'm not sure if it should be included in protocol as a protocol change,
or would some additional
command that gives this info for an
open cursor be preferrable.

Hannu



pgsql-hackers by date:

Previous
From: "Pedro J. Lobo"
Date:
Subject: configure doesn't handle --with-compiler correctly
Next
From: Zeugswetter Andreas SARZ
Date:
Subject: AW: [HACKERS] Re: Subselects open issue Nr. 5