Subject: sort by-clause in PG4.0.1

From: SEP Lutz <[email-masked]>
Date: Tue, 3 Aug 93 15:52:14 MET DST

Dear postgres developers,

I am trying to port my little POSTGRES database application
which was developed on a SUN SPARCstation using POSTGRES 4.1
(but does not use any POSTGRES 4.1-specific functionality)
to my PC running Linux 0.99 and the POSTGRES 4.0.1 Linux port by
Kai Petzke.

I was very badly surprised when realizing that queries like

	retrieve (pgu.all)
	from pgu in pg_user
	where pgu.usesuper = "f"::bool
	sort by usename using <=

failed under PG 4.0.1 for Linux with 

	parser: syntax error at or near "sort"

while

	retrieve (pg_user.all)
	where pg_user.usesuper = "f"::bool
	sort by usename using <=

runs all right.

Despite, this is serious problem for me, as all queries in
my application are entered at run-time and formulated using
tuple variables.

I tried the first version of the query with the tuple variable
on the SPARCstation using PG 4.1, and it ran alright.

Is this a bug in version 4.0.1 or a problem specific to the
Linux port of POSTGRES (perhaps because of incompatibilities between
lex/flex or yacc/bison versions)?

If it is a bug in PG 4.0.1, would you please be so kind to mail me
me which files were changed to 4.1 and a copy of these changes.
If it is a problem of the Linux port, please also send me a short notice,
and I will contact Kai Petzke about the problem.

Thank you very much in advance,

Andreas Loew
gesamic project group

-- 
SE Projektgruppe GeSAMiC      Email: [email-masked]
Fachbereich 1
Technische Hochschule Darmstadt / Germany

   When Mozart was my age, he had been dead for two years.  -- Tom Lehrer

---

From: [email-masked] (Kai Petzke)
Date: Wed, 4 Aug 93 1:06:32 MET DST

> lex/flex or yacc/bison versions)?

It is a yacc/bison incompatibility, I did not discover, before I
released the Postgres Port to Linux.  Though it is out for several
months now, noone asked me about this till one week ago -:)

As far, as I know, the thing happens only, if you have no where
clause specified.  Anyway, I will not try to reproduce your error,
because I do not have unpatched binaries.

In other words, the diffs in the end of the post fix the problem.

I will not release new 4.0.1 binaries, as I will have time to look
into the Linux 4.1 port next week (it has a serious problem, if more
then one backend is invoked, reducing its use to single user).

> and I will contact Kai Petzke about the problem.

I am Kai Petzke, don't hesitate to contact me -:)

PS: To compile the source, you may have to have to add one #include to
    src/utils/adt/regexp.c.  See the postgres.README for details, which
    is supplied with the Linux postgres distribution.

PPS: Linux 0.99pl11 runs Postgres without any kernel patching.  Just answer
     "yes" to the question, whether IPC shall be compiled into the kernel.

--------------------------------------------------------------------------------
*** src/parser/gram.y~	Sun May  2 19:01:02 1993
--- src/parser/gram.y	Sun Aug  1 00:49:12 1993
***************
*** 1433,1441 ****
  	 FROM from_list 			
  		{ 
  			$$ = $2 ; 
! 			SkipBackToTlist();
  			yychar = -1;
  			/* goto yynewstate; */
  		}
  	| /*empty*/				{ NULLTREE ; }
  	;
--- 1433,1452 ----
  	 FROM from_list 			
  		{ 
  			$$ = $2 ; 
! 			SkipBackToTlist(0);
  			yychar = -1;
  			/* goto yynewstate; */
+ 		}
+ 	/*
+ 	 * kai:
+ 	 * this is a hack to make byacc work! (The order-reversed grammar
+ 	 * does never allow a SORT after a from_clause, and byacc fails to
+ 	 * early, if it reads SORT!).
+ 	 */
+ 	| FROM from_list SORT
+ 		{
+ 			$$ = $2;
+ 			SkipBackToTlist(1);
  		}
  	| /*empty*/				{ NULLTREE ; }
  	;
*** src/parser/parse_query.c~	Sun May  2 19:06:58 1993
--- src/parser/parse_query.c	Sun Aug  1 00:55:14 1993
***************
*** 759,765 ****
  }
  
  LispValue
! SkipBackToTlist()
  {
  	extern LispValue yychar;
  	extern int yyleng;
--- 759,766 ----
  }
  
  LispValue
! SkipBackToTlist(flag)
! int flag;
  {
  	extern LispValue yychar;
  	extern int yyleng;
***************
*** 767,773 ****
  
  	/* need to put the token after the target_list back first */
  	Ch = CurScan();
! 	if((yychar == (LispValue)WHERE) || (yychar == (LispValue)SORT))
  		Ch -= yyleng;
  
  	InputFrag = target_list_place;
--- 768,774 ----
  
  	/* need to put the token after the target_list back first */
  	Ch = CurScan();
! 	if(flag || (yychar == (LispValue)WHERE) || (yychar == (LispValue)SORT))
  		Ch -= yyleng;
  
  	InputFrag = target_list_place;
*** src/parser/parse_query.h~	Thu May  6 19:09:17 1993
--- src/parser/parse_query.h	Sun Aug  1 01:36:33 1993
***************
*** 9,15 ****
  extern LispValue make_op ARGS((LispValue op, LispValue ltree, LispValue rtree, char optype));
  extern LispValue make_var  ARGS((Name relname, Name attrname));
  SkipForwardToFromList ARGS((void));
! LispValue SkipBackToTlist ARGS((void));
  LispValue SkipForwardPastFromList ARGS((void));
  StripRangeTable ARGS((void));
  extern LispValue make_const ARGS((LispValue value));
--- 9,15 ----
  extern LispValue make_op ARGS((LispValue op, LispValue ltree, LispValue rtree, char optype));
  extern LispValue make_var  ARGS((Name relname, Name attrname));
  SkipForwardToFromList ARGS((void));
! LispValue SkipBackToTlist ARGS((int flag));
  LispValue SkipForwardPastFromList ARGS((void));
  StripRangeTable ARGS((void));
  extern LispValue make_const ARGS((LispValue value));

---

From: [email-masked] (Paul M. Aoki)
Date: Tue, 03 Aug 93 12:32:59 -0700

> lex/flex or yacc/bison versions)?

kai's linux ports have substantial parser hacks to make the postgres
parser work with flex/byacc.   by an amazing coincidence, his 4.1 port 

> +        * early, if it reads SORT!).

so i would advise you to get his 4.1 port.  (it's in the same
linux archives as the 4.0.1 port.)

> me which files were changed to 4.1 and a copy of these changes.

this is not a reasonable thing to do.  the source tree structure 
changed too much from 4.0.1 to 4.1.

> and I will contact Kai Petzke about the problem.

if you have any other problems with the linux port, you had best do 
this in any case.  i'm in the process of folding in kai's changes but 
we do not support the linux ports here.
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki