4

I was using the bigquery function current_timestamp() when i discovered that you can use it without parenthesis if you want. Since it is a function, i would advocate for parenthesis, but what i find on the internet indicates that you can indeed use it without in different standards.

I found that in ANSI SQL 1992 it is indeed a function (based on this answer). Yet i did not find why it is allowed to call it without parenthesis and even if the standard advocates for parenthesis or not ? Snowflake is saying that it allows for a call without parenthesis to comply with ANSI SQL...

So does anyone knows what it is ?

Many thanks in advance !

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • 1
    i am just curious - how does it matter if you have () or not. – Koushik Roy Jul 12 '21 at 15:33
  • 1
    It's just clearer to me the type of what i'm using. If it's a function it should have a `()` at the end of the call, if it's a variable then it does not have a parenthesis since it's not a function call. I guess i'm just being influenced by my knowledge of OOP and Java. The truth is in that case it does not really matter, but i would want to standardize it across an organization and therefore i seek what is the most appropriate standard to use :) – Amaury Faure Jul 12 '21 at 15:53
  • Lookup here - might be helpful for curiosity.. https://blog.ansi.org/2018/10/sql-standard-iso-iec-9075-2016-ansi-x3-135/ – FKayani Jul 12 '21 at 16:23
  • 1
    Thanks ! The documents are quite expensive though :( – Amaury Faure Jul 13 '21 at 07:17

1 Answers1

2

Based on 2.1.2.70 F411:

<current timestamp value function> ::=
 CURRENT_TIMESTAMP [ <left paren> <timestamp precision> <right paren> ]

It is a function and (<precision>) is optional so the following are correct:

SELECT CURRENT_TIMESTAMP;

SELECT CURRENT_TIMESTAMP(3);

Based on that definition SELECT CURRENT_TIMESTAMP() shouldn't work but often is implemented.

db<>fiddle demo - MySQL vs db<>fiddle demo - PostgreSQL

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275