pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: sgarden@club.fr
Cc: pgsql-docs@lists.postgresql.org
Subject: Re: the date() function is undocumented while quite necessary
Date: Sat, 15 Feb 2020 11:36:50 -0500
Message-ID: <18379.1581784610@sss.pgh.pa.us> (raw)
In-Reply-To: <158177916388.6746.12385265846339386100@wrigleys.postgresql.org>
References: <158177916388.6746.12385265846339386100@wrigleys.postgresql.org>

PG Doc comments form <noreply@postgresql.org> 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-TYPE-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=# create table t1 (f1 timestamp);
CREATE TABLE
regression=# create index on t1 (f1::date);
ERROR:  syntax error at or near "::"
LINE 1: create index on t1 (f1::date);
                              ^
regression=# 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





view thread (2+ messages)

Message-ID: <18379.1581784610@sss.pgh.pa.us>
Permalink:  ../18379.1581784610@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18379.1581784610@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sgarden@club.fr, pgsql-docs@lists.postgresql.org
  Subject: Re: the date() function is undocumented while quite necessary
  In-Reply-To: <18379.1581784610@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox