Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Re: [INTERFACES] retrieving varchar size

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: byronn(at)insightdist(dot)com (Byron Nikolaidis)
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgreSQL(dot)org, pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: [INTERFACES] retrieving varchar size
Date: 1998-04-26 02:30:25
Message-ID: 199804260230.WAA17770@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-interfaces
> 
> Yes,  it rings a bell alright,
> 
> When you execute a multiple query (denoted by semicolans) like "set geqo to
> 'off'; show datestyle; select * from table", you get that multiple returns and
> MUST read until you get the 'I'.  If you don't, your screwed the next time you
> try and read anything cause all that stuff is still in the pipe.

Good point.  If we don't send the empty query, the queued up results get
out of sync with the requests.

One solution is to handle it the way psql does.  It keeps track of the
quotes, backslashes, and semicolons in the input string, and sends just
one query each time to the backend, and prints the results.

Now, with libpq, I think the proper solution would be to scan the input
string, and count the number of queries being send, send the whole
strings (with the multiple queries) and retrieve that many answers from
the backend, discarding all but the last result.  If you do that, I can
remove the stuff from psql.c.

> 
> Question though, I didnt think my request would have caused a major protocol
> change.  I though that the '-1' would simply be replaced by the correct size?

Well, the -1 is in attlen, which is the type length.  text, char,
varchar are all varlena(variable length)/-1.  atttypmod is the length
specified at attribute creation time.  It is similar, but not the same
as the length, and trying to put the typmod in the length field really
messes up the clarity of what is going on.  We added atttypmod to
clarify the code in the backend, and it should be sent to the front end.
Soon, maybe will have atttypmod specifiying the precision of DECIMAL, or
currency of MONEY.

As far as adding atttypmod to libpq, I say do it.  If you look in the
backend's BeginCommand(), under the Remote case label, you will see it
sending the atttypid to the front end, using the TupleDesc that was
passed to it.  Just after sending the atttyplen, I can send the
atttypmod value, which is an int16.  I can do all the backend changes. 
There are a few places where this would have to be changed in the
backend.

Other front-end libraries reading this protocol will have to change to
to accept this field.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist(at)candle(dot)pha(dot)pa(dot)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)

In response to

Responses

pgsql-hackers by date

Next:From: Bruce MomjianDate: 1998-04-26 03:26:15
Subject: Re: [HACKERS] Re: [INTERFACES] retrieving varchar size
Previous:From: Bruce MomjianDate: 1998-04-25 22:07:31
Subject: Re: [HACKERS] create operator problem

pgsql-interfaces by date

Next:From: Bruce MomjianDate: 1998-04-26 03:26:15
Subject: Re: [HACKERS] Re: [INTERFACES] retrieving varchar size
Previous:From: Patrick ShelleyDate: 1998-04-25 21:20:24
Subject: graphic-objects

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group