This is a multi-part message in MIME format.
------=_NextPart_000_01B9_01C47AD6.FBF146A0
Content-Type: text/plain;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable
Hi,
I am a developer working with many databases, as a part of my job. I use he=
avy SQL queries and have become somewhat of an expert in SQL, including tri=
cks and workarounds of the limitation of the language.
I feel like a lot of the workarounds could be avoided with adding a few new=
operators to the SQL language that should be rather easy to support but wo=
uld give a vast improvement and probably a leap of performance in many comm=
on queries. I write you about this hoping that you would support these oper=
ators (even though they are not in the ANSI) and thereby position PostGres =
as a leader and not just a follower! I personaly have a great interest in s=
eeing open source software making it big time! So please - forward this to =
one of your more technical developers/executives and hopefully I will get t=
o see it in the next version of PostGres:
1) The operator "of max":
suppose I have a table "grades" of 3 fields: class/student/grade where I st=
ore many grades of many students of many classes. I want to get the name of=
the highest scoring student in each class. Note that there may be many stu=
dents with the same grade, but for starters let's say there is a primary ke=
y of class+grade.
My query would now be:
select student from grades where class+'#'+grade in
(
select class+'#'+max(grade) from grades group by class
) a
This means working the query twice - and relying on louzy conversion of the=
grade from numerical to textual.
We could also use:
select student from grades where student in
(
select student from grades group by class
having class+'#'+grade =3D max(class+'#'+grade)
) a
This is even worse!
The optimal would be to introduce a new operator "of max" that would be use=
d as follows:
select student of max(grade) from grades group by class
simillarly one should support "of min" and "of any" (brings a representativ=
e of the group)
2) aggregated concatenation:
Traditionally the SQL language has referred from supporting order dependent=
operators from taking a role in aggregated functions. This means that sinc=
e the query: "select class, grade from grades" does not ensure the order of=
the records returned, the operation sum() is supported (i.e. select class,=
sum(grade) from grades group by class) but other operations that would be =
order dependent are not supported.
I think this approach should be revised. In many cases one would want to ge=
t a list of the student names delimited with a comma. It would be great if =
one could write:
select class, list(student, ',') from grades group by class
and get
class list
----- ----
class1 john, ruth,...
This is of course an order dependent operation so the syntax can either be:
select class, list(student, ',') from grades group by class order by studen=
t, grade
in which case the list would be ordered before the list is created, or if n=
o particular order is requested the concatenation of the names should be in=
an arbitrary order.
Well - that's all for now :-)
Good luck!
Ram
------=_NextPart_000_01B9_01C47AD6.FBF146A0
Content-Type: text/html;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dwindows-125=
5">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I am a developer working with many databas=
es, as a
part of my job. I use heavy SQL queries and have become somewhat of an expe=
rt in
SQL, including tricks and workarounds of the limitation of the
language.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I feel like a lot of the workarounds could=
be
avoided with adding a few new operators to the SQL language that should be=
rather easy to support but would give a vast improvement and probably a lea=
p of
performance in many common queries. I write you about this hoping that you =
would
support these operators (even though they are not in the ANSI) and thereby=
position PostGres as a leader and not just a follower! I personaly hav=
e a
great interest in seeing open source software making it big time! So please=
-
forward this to one of your more technical developers/executives and hopefu=
lly I
will get to see it in the next version of PostGres:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>1) The operator "of max":<BR>suppose=
I have a
table "grades" of 3 fields: class/student/grade where I store many grades o=
f
many students of many classes. I want to get the name of the highest scorin=
g
student in each class. Note that there may be many students with the same g=
rade,
but for starters let's say there is a primary key of class+grade.</FONT></D=
IV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>My query would now be:<BR>select student f=
rom
grades where class+'#'+grade in <BR>(<BR> select
class+'#'+max(grade) from grades group by class<BR>) a</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>This means working the query twice - and r=
elying on
louzy conversion of the grade from numerical to textual.<BR>We could also=
use:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>select student from grades where student i=
n
<BR>(<BR> select student from grades group by class <BR> having=
class+'#'+grade =3D max(class+'#'+grade)<BR>) a</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>This is even worse!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>The optimal would be to introduce a new op=
erator
"of max" that would be used as follows:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>select student of max(grade) from grades g=
roup by
class</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>simillarly one should support "of min" and=
"of any"
(brings a representative of the group)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>2) aggregated concatenation:<BR>Traditiona=
lly the
SQL language has referred from supporting order dependent operators from ta=
king
a role in aggregated functions. This means that since the query: "select cl=
ass,
grade from grades" does not ensure the order of the records returned, the=
operation sum() is supported (i.e. select class, sum(grade) from grades gro=
up by
class) but other operations that would be order dependent are not
supported.<BR>I think this approach should be revised. In many cases one wo=
uld
want to get a list of the student names delimited with a comma. It would be=
great if one could write:<BR>select class, list(student, ',') from grades g=
roup
by class<BR>and get</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>class list<BR>----- ----<BR>cl=
ass1
john, ruth,...<BR>.<BR>.<BR>.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>This is of course an order dependent opera=
tion so
the syntax can either be:<BR>select class, list(student, ',') from grades g=
roup
by class order by student, grade<BR>in which case the list would be ordered=
before the list is created, or if no particular order is requested the
concatenation of the names should be in an arbitrary order.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Well - that's all for now :-)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Good luck!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Ram</FONT></DIV></BODY></HTML>
------=_NextPart_000_01B9_01C47AD6.FBF146A0--
