Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEaDM-0006jf-H4 for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Sep 2019 14:30:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iEaDJ-0005wX-Kw for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Sep 2019 14:30:17 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEaDI-0005sP-Fc for pgsql-hackers@lists.postgresql.org; Sun, 29 Sep 2019 14:30:17 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iEaDE-0003Uv-Jm; Sun, 29 Sep 2019 14:30:15 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 9941421C2599; Sun, 29 Sep 2019 17:30:11 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (not verified)) by mail.postgrespro.ru (Postfix) with ESMTPSA id C7B7321C271A; Sun, 29 Sep 2019 17:30:10 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1569767411; bh=wE41dNNBJzyg5cEql72YOOD4ocN9P+DQphqf83nhA8Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc; b=VfDhCLYLE+wt0fLnXLauig0mCasNEpTyUyVgL/OPq0S3dbe+B9IfadGGibb7cwJ0c KAJF0+AmgMrYGl4NAFYvqWTfDHdVQRxC21n/hAa8/fMMGCf3l1ptQankqoPyRbEARB aFhM1fZGJn0wst6rLhh6b1LCFkgWC/t/5tfyAaCc= Received: by mail-io1-f41.google.com with SMTP id w12so2804251iol.11; Sun, 29 Sep 2019 07:30:10 -0700 (PDT) X-Gm-Message-State: APjAAAVwrlG1iOdKU/QgbHtCj9/LZXG3AAtLQ3QgBv0D/RQB8lHgfY66 e/oN3ylPHRpWfzcQ13ccbwuV5D0+2Afd8MYU8mc= X-Google-Smtp-Source: APXvYqyhbUQxX1HBYpNvPHG3Nr1UJvDYwYyPjNCLzY14C6QNQD+BCr0mIvI2rmwjla1nyJCzE4xKljOHJFy9gKqV+8U= X-Received: by 2002:a92:995a:: with SMTP id p87mr15757579ili.115.1569767408367; Sun, 29 Sep 2019 07:30:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Korotkov Date: Sun, 29 Sep 2019 17:29:56 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: pgsql: Implement jsonpath .datetime() method To: Nikita Glukhov Cc: pgsql-committers , Alexander Korotkov , Tom Lane , pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Sep 27, 2019 at 6:58 PM Nikita Glukhov wrote: > On Thu, Sep 26, 2019 at 2:57 AM Tom Lane wrote: > > * More generally, it's completely unclear why some error conditions > > are thrown as errors and others just result in returning *have_error. > > In particular, it seems weird that some unsupported datatype combinations > > cause hard errors while others do not. Maybe that's fine, but if so, > > the function header comment is falling down on the job by not explaining > > the reasoning. > > All cast errors are caught by jsonpath predicate. Comparison of the > uncomparable datetime types (time[tz] to dated types) also returns Unknown. > And only if datatype conversion requires current timezone, which is not > available in immutable family of jsonb_xxx() functions, hard error is thrown. > This behavior is specific only for our jsonpath implementation. But I'm > really not sure if we should throw an error or return Unknown in this case. I'd like to share my further thoughts about errors. I think we should suppress errors defined by standard and which user can expect. So, user can expect that wrong date format causes an error, division by zero causes an error and so on. And those errors are defined by standard. However, we error is caused by limitation of our implementation, then suppression doesn't look right to me. For instance. # select jsonb_path_query('"1000000-01-01"', '$.datetime() > "2020-01-01 12:00:00".datetime()'::jsonpath); jsonb_path_query ------------------ null (1 row) # select '1000000-01-01'::date > '2020-01-01 12:00:00'::timestamp; ERROR: date out of range for timestamp So, jsonpath behaves like 1000000 is not greater than 2020. This looks like plain false. And user can't expect that unless she is familiar with our particular issues. Now I got opinion that such errors shouldn't be suppressed. We can't suppress *every* error. If trying to do this, we can come to an idea to suppress OOM error and return garbage then, which is obviously ridiculous. Opinions? ------ Alexander Korotkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company