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

Re: Yikes! Bitten by line length?

From: Ken Corey <ken(at)kencorey(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Yikes! Bitten by line length?
Date: 2001-01-18 18:55:22
Message-ID: 3A673C1A.3A572C98@kencorey.com (view raw or flat)
Thread:
Lists: pgsql-novice
Tom Lane wrote:
> Ken Corey <ken(at)kencorey(dot)com> writes:
> > Drat!  Thought this wa identified...but sure enough it's still causing troubles.  Will report shortly.
> 
> Do you mean your previous description was incorrect, or that it is
> correct but there are more squirrelies besides that one?  If what you
> said was correct as far as it went, then we do have a bug to fix,
> I think.  plpgsql should either work or generate a reasonable error
> message when the actual parameter length exceeds the declared length
> of the formal parameter.
> 
> Right offhand, I would have said that the declared length of a function
> parameter would be completely ignored, but perhaps I am mistaken ...

Aha.  Well.  Finally got to the bottom of it, and got it all fixed.

There were two problems.

1) Problem: Under Solaris, when entering a really long sql parameter
into psql, the first bytes would be chopped off:

GRE=# select
I_SESSION(null,'1',2,'E2K','0x637B9C8B443E9AA0AF4C696D7E8AB27B4FA57B5A6DBDD29851B74BDE5D97A3995F8F8A825F8B4D95D7687CAE94E77F809B589363685A718B72A28C90AA872936297B4020360B46752B2E2042172232171C59F730193153466B2F4A42270E563A29FF4ED30C47E340396056691B1485512D1F3E2E2554124D2D47821E3BF86031335C24444E00063112644D41F09C6F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
GRE'# ');
ERROR:  parser: parse error at or near
"000000000000000000000000000000000"
GRE=#

Cause:
Solaris' fgets function *only* returns the last part of a string if the
string is over 256 bytes!  The test was this little program:

#include <stdio.h>
int main(int argc,char **argv) {
  char line[1024];
  while((fgets(line,1024,stdin)) != EOF) {
    printf("Got '%s'\n",line);
  }
}

Enter in really big lines (> 256 characters), and you'll see what I
mean.

Solution: 

The fix is to install the GNU Readline library, and recompile postgres
to use it.  Job done, and the interface is *much* nicer, now.

2) The libpq problem was my mis-handling of pointers.  Gotta love C.  As
near as I can tell, it's working okay now (although I think I'm getting
some error messages back that I should explore, at least it's not
core-dumping).

-Ken

In response to

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2001-01-18 19:00:01
Subject: Re: Yikes! Bitten by line length?
Previous:From: Tom LaneDate: 2001-01-18 18:40:00
Subject: Re: Novice lo_import problem (7.0.3)

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