Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qsPpj-007wu5-JG for pgsql-novice@arkaria.postgresql.org; Mon, 16 Oct 2023 15:48:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qsPph-0029KW-0S for pgsql-novice@arkaria.postgresql.org; Mon, 16 Oct 2023 15:48:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qsPkI-00231Z-Gj for pgsql-novice@lists.postgresql.org; Mon, 16 Oct 2023 15:43:07 +0000 Received: from mail-yw1-f174.google.com ([209.85.128.174]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qsPkE-000m4M-QQ for pgsql-novice@lists.postgresql.org; Mon, 16 Oct 2023 15:43:05 +0000 Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-5a7afd45199so59194177b3.0 for ; Mon, 16 Oct 2023 08:43:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697470981; x=1698075781; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zaCQ3Z0n3Lgv9RxVoKXNsOyrof7r0hUDTy1Q28HSKNU=; b=U+lQsvgTuSW3e7ae93YlM5WBJGctFlQAtOsqLFFh9DtDbNs9u038narsEpzJKOzV/o d2Y5tnWOwoTg71AvbUfdFmYPcX1DDHDlLync5thrcWP/oKklFrja3PzhQ8HW4/Vo3N3t U7z7f0ve1CY4nwJijmxiCNH6GUPhGWqbjuz2mHh1rNpJ7S2PZ8XqBfABdweh2lRpXv4M eynXwrLNLNw71mj+c6gKMAUhdDQ6auA9n1iB1quRJA95EzINzsLhTkQaqkM7+R7YUhzp h/CxApSH3rFqwOYjukz0Wb325YbjQE9D7OVJfXJRrhpIrOAALpQL0v8hXrSDjb8LIKcE 6uDw== X-Gm-Message-State: AOJu0YyToCVI2nusUDaxDqEvo5VNo5aMUz8BdKUJhTKgvOTJrG0q+L1p wJvziIJBmd1LvmLmvBq/9HbhqfkwJy57 X-Google-Smtp-Source: AGHT+IFwyhhv07WRxLDOGeqg3BRbW/h9p+lNg+gKdXHSUP4OJvcp38FMCcopD0NkQhL5vMwgVwExeQ== X-Received: by 2002:a05:690c:d8f:b0:5a8:78b0:a9fd with SMTP id da15-20020a05690c0d8f00b005a878b0a9fdmr4569839ywb.29.1697470980920; Mon, 16 Oct 2023 08:43:00 -0700 (PDT) Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com. [209.85.128.172]) by smtp.gmail.com with ESMTPSA id c3-20020a0df303000000b0059b17647dcbsm2258499ywf.69.2023.10.16.08.43.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Oct 2023 08:43:00 -0700 (PDT) Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-5a87ac9d245so14131277b3.3 for ; Mon, 16 Oct 2023 08:43:00 -0700 (PDT) X-Received: by 2002:a81:ae1c:0:b0:5a7:b53f:c304 with SMTP id m28-20020a81ae1c000000b005a7b53fc304mr20334751ywh.37.1697470980465; Mon, 16 Oct 2023 08:43:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Cory Albrecht Date: Mon, 16 Oct 2023 11:42:49 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Is `DATE` a function? To: jinser Cc: pgsql-novice@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000cead640607d7428f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000cead640607d7428f Content-Type: text/plain; charset="UTF-8" Rather than `SELECT DATE();` you likely want `SELECT NOW();` On Sat, Oct 7, 2023, 09:20 jinser wrote: > Hello, Friends, > > Use it like a normal function: > > playground=# SELECT DATE(); > ERROR: function date() does not exist > LINE 1: SELECT DATE(); > ^ > HINT: No function matches the given name and argument types. You > might need to add explicit type casts. > > playground=# SELECT DATE('2022-01-13'); > date > ------------ > 2022-01-13 > (1 row) > > Another reason I think this is a function is that other types don't > seem to have the same behavior: > > playground=# SELECT integer('123'); > ERROR: syntax error at or near "(" > LINE 1: SELECT integer('123'); > ^ > > The Table 9.33. Date/Time Functions in the documentation > ( > https://www.postgresql.org/docs/16/functions-datetime.html#FUNCTIONS-DATETIME-TABLE > ) > doesn't mention this... > If I missed it, where should I find the description? Or maybe it > actually should be in this table? > > Thanks in advance. > > > --000000000000cead640607d7428f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Rather than `SELECT DATE();` you likely want `SELECT NOW(= );`

On Sat, Oct 7, 2023, 09:20 jinser <aimer@purejs.icu> wrote:
Hello, Friends,

Use it like a normal function:

playground=3D# SELECT DATE();
ERROR:=C2=A0 function date() does not exist
LINE 1: SELECT DATE();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^
HINT:=C2=A0 No function matches the given name and argument types. You
might need to add explicit type casts.

playground=3D# SELECT DATE('2022-01-13');
=C2=A0 =C2=A0 date
------------
=C2=A02022-01-13
(1 row)

Another reason I think this is a function is that other types don't
seem to have the same behavior:

playground=3D# SELECT integer('123');
ERROR:=C2=A0 syntax error at or near "("
LINE 1: SELECT integer('123');
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 ^

The Table 9.33. Date/Time Functions in the documentation
(https= ://www.postgresql.org/docs/16/functions-datetime.html#FUNCTIONS-DATETIME-TA= BLE)
doesn't mention this...
If I missed it, where should I find the description? Or maybe it
actually should be in this table?

Thanks in advance.


--000000000000cead640607d7428f--