Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id E1944B5DBC6 for ; Mon, 13 Jun 2011 13:07:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 08299-07 for ; Mon, 13 Jun 2011 16:07:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f46.google.com (mail-ew0-f46.google.com [209.85.215.46]) by mail.postgresql.org (Postfix) with ESMTP id 0A068B5D80A for ; Mon, 13 Jun 2011 13:07:38 -0300 (ADT) Received: by ewy4 with SMTP id 4so1653128ewy.19 for ; Mon, 13 Jun 2011 09:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=owJ9JLVkswA2CJ+FxJUbKBXdcS9ACou01CC/sZgf7ws=; b=eR28XKbr3a7FMhjTYi//O/5WqED/KEBa8oaKhkWC3WbNZx2KmVDJrSMA22/BrvIJQi CDsjhDxDp0r01hX24Btg1ALoRzanjAs0KI0zQuh/V3GYi7NqjFacq3OZ36INGc56OS2E OFlxaY9wyboDyJXos9ObbCktvTQeUWK1qKW4w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=bArvi/T+DbsuV5lHUgKEzFnvL2z5E3jFWh4VLAsQ7k2uNSt2J22zGWhIjSuO85yS+j vUtZTujUD5tEr13rWjbmM5Z2yzA+vqzY1soxGPIOkYD8J1lMRo4oVzuWVuDL42RzvUhG cWtyaUyi/yt4B773l+353jYHq9zY7VOgnPw+M= MIME-Version: 1.0 Received: by 10.14.98.71 with SMTP id u47mr2368963eef.247.1307981256758; Mon, 13 Jun 2011 09:07:36 -0700 (PDT) Received: by 10.14.96.4 with HTTP; Mon, 13 Jun 2011 09:07:36 -0700 (PDT) In-Reply-To: References: Date: Mon, 13 Jun 2011 12:07:36 -0400 Message-ID: Subject: Re: 7.2. Table Expressions FULL join is only supported with merge-joinable join conditions From: Robert Haas To: Grzegorz Szpetkowski Cc: pgsql-docs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/38 X-Sequence-Number: 6812 On Mon, May 16, 2011 at 7:32 PM, Grzegorz Szpetkowski wrote: > http://www.postgresql.org/docs/9.0/static/queries-table-expressions.html > > "The join condition specified with ON can also contain conditions that > do not relate directly to the join. This can prove useful for some > queries but needs to be thought out carefully. For example: > > =3D> SELECT * FROM t1 LEFT JOIN t2 ON t1.num =3D t2.num AND t2.value =3D = 'xxx';" > > Can you add information about FULL JOIN in doc there ? I am trying to > run such query: > > SELECT * FROM t1 FULL JOIN t2 ON t1.num =3D t2.num AND t2.value =3D 'xxx'= ; > ERROR: =A0FULL JOIN is only supported with merge-joinable join conditions > > I mean add something like: "Note that you can't use such conditions > with FULL JOIN, only equality of selected columns is supported with > this type". This works in 9.1. A possibly relevant point is that the semantics are not what you might think: rhaas=3D# create table t1 (num int, value text); CREATE TABLE rhaas=3D# create table t2 (num int, value text); CREATE TABLE rhaas=3D# insert into t1 values (1, 'yyy'), (2, 'yyy'); INSERT 0 2 rhaas=3D# insert into t2 values (2, 'yyy'), (3, 'yyy'); INSERT 0 2 rhaas=3D# select * from t1 full join t2 on t1.num =3D t2.num and t2.value = =3D 'xxx'; num | value | num | value -----+-------+-----+------- 1 | yyy | | 2 | yyy | | | | 2 | yyy | | 3 | yyy (4 rows) It's very possible that a user who is writing this meant one of the followi= ng: select * from t1 full join (select * from t2 where t2.value =3D 'xxx') t2 on t1.num =3D t2.num; select * from t1 full join t2 on t1.num =3D t2.num WHERE t2.value =3D 'xxx'= ; ...which are not equivalent to each other, or to the original query. It'd be nice to document this better, but I don't have a clear feeling for exactly what is needed. --=20 Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company