Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n2iPW-0000VP-Lo for pgsql-general@arkaria.postgresql.org; Wed, 29 Dec 2021 23:31:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n2iPV-0002JD-CE for pgsql-general@arkaria.postgresql.org; Wed, 29 Dec 2021 23:31:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n2iPV-0002J4-2H for pgsql-general@lists.postgresql.org; Wed, 29 Dec 2021 23:31:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n2iPS-0002d6-Ua for pgsql-general@lists.postgresql.org; Wed, 29 Dec 2021 23:31:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1BTNV4ig2179736; Wed, 29 Dec 2021 18:31:04 -0500 From: Tom Lane To: Michael Lewis cc: PostgreSQL General Subject: Re: Default values in functions In-reply-to: References: Comments: In-reply-to Michael Lewis message dated "Wed, 29 Dec 2021 15:59:10 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2179734.1640820664.1@sss.pgh.pa.us> Date: Wed, 29 Dec 2021 18:31:04 -0500 Message-ID: <2179735.1640820664@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michael Lewis writes: > I am on PG 13.4 and found some surprising behavior with default values. Can > anyone give insight why the last two cases (especially the last one) do not > give the result I expected? If I uncomment the line to set pArrayToCheck > with coalesce, then it gives the expected results though. I don't think your concerns have anything to do with the default parameters, but rather with the operations the function is performing: > SELECT icount ( pArrayToCheck ) = 0 INTO lReturnValue; You didn't say what icount() is, but if it's the one from contrib/intarray, it's STRICT meaning it'll return NULL, not zero, for a null array input. Judging from your expected_results, you want something more like SELECT coalesce(icount(pArrayToCheck), 0) = 0 INTO lReturnValue; (Or IOW, null::int[] is not at all the same thing as array[]::int[].) > SELECT pTimeToDisplay AT TIME ZONE 'UTC' INTO pTimeToDisplay; This is very unlikely to produce anything sane. The AT TIME ZONE construct produces a timestamp-without-time-zone, which will then be rotated per your TimeZone setting while coercing it back to timestamp-with-time-zone for assignment to the output parameter. You'll end up with a net rotation equal to your local zone's GMT offset. For example: postgres=# show timezone; TimeZone ------------------ America/New_York (1 row) postgres=# select CURRENT_DATE::timestamptz; current_date ------------------------ 2021-12-29 00:00:00-05 (1 row) postgres=# select CURRENT_DATE::timestamptz AT TIME ZONE 'UTC'; timezone --------------------- 2021-12-29 05:00:00 (1 row) postgres=# select (CURRENT_DATE::timestamptz AT TIME ZONE 'UTC')::timestamptz; timezone ------------------------ 2021-12-29 05:00:00-05 (1 row) I have no idea what you were hoping to accomplish there, so I have no suggestion what to do instead. regards, tom lane