Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WXBFI-000416-N5 for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Apr 2014 15:14:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WXBFF-00078h-Vh for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Apr 2014 15:13:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WX9R9-0000Xg-Cp for pgsql-bugs@postgresql.org; Mon, 07 Apr 2014 13:18:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WX9R5-0006j8-EP for pgsql-bugs@postgresql.org; Mon, 07 Apr 2014 13:18:05 +0000 MIME-Version: 1.0 Subject: BUG #9896: Bug in FULL OUTER JOIN To: pgsql-bugs@postgresql.org From: sqlpro@sqlspot.com Date: Mon, 07 Apr 2014 13:17:05 +0000 Message-ID: <20140407131705.342.75513@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.5 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 9896 Logged by: SQLpro Email address: sqlpro@sqlspot.com PostgreSQL version: 9.3.4 Operating system: Windows Description: According to ISO standard SQL there is no limitation in predicat ON for JOIN operator. But PostGreSQL is unable to join tables in the FULL OUTER mode when predicate ON is not sargable. here is an example : CREATE TABLE T_CLIENT_CLI --> customers (CLI_ID INT PRIMARY KEY, CLI_SIREN CHAR(9) NOT NULL UNIQUE, CLI_ENSEIGNE VARCHAR(16) NOT NULL); CREATE TABLE T_PROSPECT_PSP --> sale perspectives (PSP_ID INT PRIMARY KEY, PSP_SIREN CHAR(9) NOT NULL UNIQUE, PSP_ENSEIGNE VARCHAR(16) NOT NULL); We want to join on SIREN (national French firm number) or, in the case of mistake in this number, on the name (enseigne). Some datas : INSERT INTO T_CLIENT_CLI VALUES (1, '123456789', 'IBM'), (2, '111111111', 'Microsoft'), (3, '999555111', 'SAP'); INSERT INTO T_PROSPECT_PSP VALUES (101, '123456789', 'IBM'), (102, '555555555', 'Microsoft'), (103, '777777777', 'Amazon'), (104, '444444444', 'Google'); This query answer exactly to the question : SELECT * FROM T_CLIENT_CLI AS C FULL OUTER JOIN T_PROSPECT_PSP AS P ON C.CLI_SIREN = P.PSP_SIREN OR C.CLI_ENSEIGNE = P.PSP_ENSEIGNE; The result would be : CLI_ID CLI_SIREN CLI_ENSEIGNE PSP_ID PSP_SIREN PSP_ENSEIGNE ----------- --------- ---------------- ----------- --------- ---------------- 1 123456789 IBM 101 123456789 IBM 2 111111111 Microsoft 102 555555555 Microsoft 3 999555111 SAP NULL NULL NULL NULL NULL NULL 103 777777777 Amazon NULL NULL NULL 104 444444444 Google But PG throw an exception : ERREUR: FULL JOIN is only supported with merge-joinable or hash-joinable join conditions État SQL :0A000 This is the case in version 9.1.2 too. It seems that is the case in any version of PG... By comparizon, this query guive the exact answer in : - MS SQL Server since version 2000 to 2014 (2005, 2008/2008R2, 2012). - Oracle 11G Thanks -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs