Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aTx3J-0006fo-7C for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Feb 2016 19:37:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aTx3I-0004uJ-Kc for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Feb 2016 19:37:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aTx2Z-00048i-UD for pgsql-bugs@postgresql.org; Thu, 11 Feb 2016 19:36:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aTx2X-0006Bd-9H for pgsql-bugs@postgresql.org; Thu, 11 Feb 2016 19:36:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u1BJZqtM000504; Thu, 11 Feb 2016 14:35:52 -0500 From: Tom Lane To: "Zakharov, Andrey" cc: "pgsql-bugs@postgresql.org" Subject: Re: SQL parser ubnormal behaviour In-reply-to: <3F693CCDF87C9742826D43FFF9F366BE7D72D456@oro-mbox-01.luxoft.com> References: <3F693CCDF87C9742826D43FFF9F366BE7D72D456@oro-mbox-01.luxoft.com> Comments: In-reply-to "Zakharov, Andrey" message dated "Thu, 11 Feb 2016 08:23:09 +0000" Date: Thu, 11 Feb 2016 14:35:52 -0500 Message-ID: <503.1455219352@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) 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 "Zakharov, Andrey" writes: > 1) > SELECT COUNT(app.paapl_application_id) OVER() AS totalCount, > app.edcit_citizenship_id, app.paapl_application_id, app.paapl_blocker_resolution_check, > app.paapl_dob, app.paapl_gender, app.paapl_inn, app.paapl_is_fprint_pkg_completed, > app.paapl_is_migreg_pkg_completed, app.paapl_last_name, app.paapl_last_name_latin, > app.paapl_name, app.paapl_name_latin, app.paapl_note, app.paapl_patent_decision_comment, > app.paapl_phase_start_ts, app.paapl_processing_start, app.paapl_second_name, app.paapl_second_name_latin, > app.paapl_sf_is_ext_wait_complete, app.paapl_status_ts, app.paapl_type, app.pablk_application_blocker_id, > doc.padoc_number, doc.padoc_series, app.paopr_last_name_locked, app.paopr_login_locked, app.paopr_name_locked, > app.paopr_second_name_locked, passport.pascn_document_scan_id_trans, app.pasts_status_id > FROM pa_application AS app > LEFT JOIN pa_document AS doc > ON app.paapl_application_id = doc.paapl_application_id > AND (doc.padtp_document_type_id = 5) > LEFT JOIN pa_passport AS passport > ON doc.padoc_document_id = passport.padoc_document_id > Inner join pa_application_indicator as ind > on ind.paapl_application_id=app.paapl_application_id > WHERE (app.pasts_status_id = 3) and ind.paidc_ppot_sent='Y' and ind.paidc_ppot_decision_made='N' > GROUP BY app.paapl_application_id, doc.padoc_number, doc.padoc_series, passport.pascn_document_scan_id_trans > ORDER BY paapl_application_id LIMIT 10 > ; > Expected result: an SQL parser error because at least the set columns in the resultset must be the same as in the "group by" section. Probably, the reason the parser accepts this query is that the GROUP BY columns include the primary keys of all three tables. If so, that is not a bug, it's a feature --- one required by the SQL standard, in fact. > 2) > select *--count(*) > from pa_application_event ae > where ae.paeve_event_id = 23 > and ae.paevt_event_time between '2016-02-10 08:00:00' and '2016-02-10 19:59:59' > and ae.paapl_application_id = > ( > select paapl_application_id > where paevt_parameters like '%murzinaaa%' > ) > Expected result: an SQL parser error because FROM keyword is missing in the subquery and run-time error because there is equal sign after "paapl_application_id" for the subquery that returns many rows. This is not a bug either. Postgres does not require a FROM clause. (If you're used to Oracle, you can imagine that there's an implicit "FROM DUAL" in there.) paapl_application_id and paevt_parameters are being taken as outer references, so you get either the current value of paapl_application_id or NULL depending on whether the LIKE condition is satisfied. In no case would you get multiple rows out of the sub-select, so there is no reason for a run-time error. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs