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 1j30RL-0007Lj-91 for pgsql-docs@arkaria.postgresql.org; Sat, 15 Feb 2020 16:37:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j30RJ-0005JN-Eu for pgsql-docs@arkaria.postgresql.org; Sat, 15 Feb 2020 16:37:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j30RJ-0005Gs-3U for pgsql-docs@lists.postgresql.org; Sat, 15 Feb 2020 16:37:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j30RC-0001VO-FW for pgsql-docs@lists.postgresql.org; Sat, 15 Feb 2020 16:37:07 +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 01FGaoNa018380; Sat, 15 Feb 2020 11:36:50 -0500 From: Tom Lane To: sgarden@club.fr cc: pgsql-docs@lists.postgresql.org Subject: Re: the date() function is undocumented while quite necessary In-reply-to: <158177916388.6746.12385265846339386100@wrigleys.postgresql.org> References: <158177916388.6746.12385265846339386100@wrigleys.postgresql.org> Comments: In-reply-to PG Doc comments form message dated "Sat, 15 Feb 2020 15:06:03 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18378.1581784610.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 15 Feb 2020 11:36:50 -0500 Message-ID: <18379.1581784610@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Doc comments form writes: > I can't find anywhere the documentation of the SQL DATE() function which > extracts the date part out of a timestamp. It's a type cast written in function-like syntax, as documented in https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-TY= PE-CASTS We don't really encourage that notation, because it's confusing and it doesn't work for every possible type name, which is why you won't find it mentioned very many places. > Please note that according to my tests, one can't use the cast operator = when > defining expression-based indexes, while the date(column) expression is > accepted. You can if you put parentheses around it: regression=3D# create table t1 (f1 timestamp); CREATE TABLE regression=3D# create index on t1 (f1::date); ERROR: syntax error at or near "::" LINE 1: create index on t1 (f1::date); ^ regression=3D# create index on t1 ((f1::date)); CREATE INDEX This is per the restriction explained in the CREATE INDEX docs, that any expression-to-be-indexed that doesn't look like a function call requires parentheses. https://www.postgresql.org/docs/current/indexes-expressional.html https://www.postgresql.org/docs/current/sql-createindex.html regards, tom lane