Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agoj8-0005U8-BX for pgsql-sql@arkaria.postgresql.org; Fri, 18 Mar 2016 07:21:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1agoj7-0000cl-Sh for pgsql-sql@arkaria.postgresql.org; Fri, 18 Mar 2016 07:21:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1agoi8-0007yG-HG for pgsql-sql@postgresql.org; Fri, 18 Mar 2016 07:20:40 +0000 Received: from mail.bezdrat.net ([213.250.192.15]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agoi5-0000Yj-1D for pgsql-sql@postgresql.org; Fri, 18 Mar 2016 07:20:39 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.bezdrat.net (Postfix) with ESMTP id DC27F222; Fri, 18 Mar 2016 08:20:34 +0100 (CET) X-Virus-Scanned: amavisd-new at fortech.cz Received: from mail.bezdrat.net ([127.0.0.1]) by localhost (mail.bezdrat.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n1gPFdX3Hn5n; Fri, 18 Mar 2016 08:20:33 +0100 (CET) Received: from [172.16.16.38] (edas.lit.cz [213.250.198.38]) (Authenticated sender: edlman@bezdrat.net) by mail.bezdrat.net (Postfix) with ESMTPSA id 511EE22E; Fri, 18 Mar 2016 08:20:31 +0100 (CET) Subject: Re: Fwd: Enhancement to SQL query capabilities To: Andrew Smith , "David G. Johnston" References: Cc: pgsql-sql@postgresql.org From: Martin Edlman Message-ID: <56EBAC3E.7060401@gmail.com> Date: Fri, 18 Mar 2016 08:20:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="------------ms080206090100030701090802" X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a cryptographically signed message in MIME format. --------------ms080206090100030701090802 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Andrew, what about NATURAL JOIN? I think that's the shortest possible way to writ= e joined SQL. It needs you to use same column names across joined tables on= which you want to join, but it should not be a problem. See http://www.postgresql.org/docs/9.5/static/sql-select.html CREATE TABLE holiday_region ( region_id serial NOT NULL PRIMARY KEY, region_name text NOT NULL UNIQUE ); CREATE TABLE holiday_group ( group_id serial NOT NULL PRIMARY KEY, group_name text NOT NULL UNIQUE, region_id integer NOT NULL references holiday_region(region_id) ); CREATE TABLE holidays ( holidays_id serial NOT NULL PRIMARY KEY, holidays_description text, group_id integer NOT NULL references holiday_group(group_id), holidays_day smallint NOT NULL, holidays_month smallint NOT NULL, holidays_year integer NOT NULL, UNIQUE (group_id, holidays_year, holidays_month, holidays_day) ); Then you write SELECT * FROM holidays NATURAL JOIN holiday_group NATURAL JOIN holiday_region Regards, Martin > Apologies, forgot to reply all: > =20 >=20 > In order to get the data I want in postgres, I need to do this:= >=20 > select h.Day, h.Description, h.Month, h.Year, g.Name, r.Name fr= om > Holidays h, HolidayGroup g, HolidayRegion r where h.HolidayGrou= p =3D > g.Id and g.HolidayRegion =3D r.Id=20 >=20 >=20 > I suggest learning ANSI join syntax. >=20 > FROM holiday h > JOIN holidaygroup g on (h.id =3D g.id ) = > =20 >=20 >=20 > Any particular reason why? This creates a longer query string than the = one > I listed and they both give the same result: >=20 > select h.Day, h.Description, h.Month, h.Year, g.Name, r.Name from Holid= ays > h join HolidayGroup g on h.HolidayGroup =3D g.id join > HolidayRegion r on g.HolidayRegion =3D r.id >=20 > Does using a join make the query execute faster, or is it just a 'more > accepted' query standard? I've been so used to our custom syntax that I= > haven't written a 'real' SQL query in more than a decade. > =20 >=20 >=20 > Even if this is something that would be committed (I have my doubt= s > and generally don't think it should be) you'd still end up writing = it > because I am near certain no one else would be so inclined. >=20 > Given you are not adding any new capabilities and making significan= t > changes to parsing code, the barrier for entry is very high. If th= e > syntax was standard then work on using meta-data to auto-resolve th= e > joins might be worthy of inclusion. >=20 >=20 > I would have thought that being able to reduce the complexity of long S= QL > statements would be seen as a new capability, but if it isn't desirable= > then I'll download the code and start looking into it. At the very leas= t > I'll probably have to provide a homebrew alternative to psql as we've g= ot > heaps of scripts written in this syntax which will take a very long tim= e to > port across to standard SQL. > =20 >=20 >=20 > I can't find any information on the postgres website about a w= ay > to submit feature requests/enhancements, only to report bugs. I= s > there a formal mechanism to request new functionality? >=20 >=20 > Most requests that are not bugs should go to -general unless one of= the > other lists seems more appropriate. Discussions about patches occu= r on > -hackers. >=20 > =20 > Thanks, will keep that in mind for my next dumb idea :-)=20 >=20 >=20 --------------ms080206090100030701090802 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: Elektronicky podpis S/MIME MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCC BbwwggW4MIIDoKADAgECAgMRx5EwDQYJKoZIhvcNAQELBQAweTEQMA4GA1UEChMHUm9vdCBD QTEeMBwGA1UECxMVaHR0cDovL3d3dy5jYWNlcnQub3JnMSIwIAYDVQQDExlDQSBDZXJ0IFNp Z25pbmcgQXV0aG9yaXR5MSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0QGNhY2VydC5vcmcwHhcN MTYwMjI1MDcyMTU2WhcNMTYwODIzMDcyMTU2WjBlMRgwFgYDVQQDEw9DQWNlcnQgV29UIFVz ZXIxITAfBgkqhkiG9w0BCQEWEmVkbG1hbkBiZXpkcmF0Lm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