[ https://issues.apache.org/jira/browse/CALCITE-5352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17626908#comment-17626908 ]
carton.swing commented on CALCITE-5352: --------------------------------------- [~libenchao] If you run this statement in psql(PostgreSQL Client): {code:java} postgres=# SELECT EXTRACT(WEEK FROM TIMESTAMP '2022-10-31'); extract --------- 44 (1 row) postgres=# SELECT DATE_PART(WEEK, TIMESTAMP '2022-10-31'); ERROR: column "week" does not exist LINE 1: SELECT DATE_PART(WEEK, TIMESTAMP '2022-10-31'); {code} you will get an error because PostgreSQL only accept text field with DATE_PART function for the first argument. But in EXTRACT function, the argument can be both a quoted string or identifier. But I wonder if current support for DATE_PART function is only for redshift cause I found this comment in test file: [https://github.com/apache/calcite/blob/calcite-1.32.0/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java#L175~L177] {code:java} /** In Redshift, PostgreSQL the DATEADD, DATEDIFF and DATE_PART functions have * ordinary function syntax except that its first argument is a time unit * (e.g. DAY). We must not parse that first argument as an identifier. */ {code} > Babel parser does not recognize character literal with DATE_PART function > ------------------------------------------------------------------------- > > Key: CALCITE-5352 > URL: https://issues.apache.org/jira/browse/CALCITE-5352 > Project: Calcite > Issue Type: Bug > Reporter: carton.swing > Priority: Major > > While using babel parser(calcite-babel's SqlBabelParserImpl) to parse > PostgreSQL syntax: > {code:java} > planner.parse("SELECT DATE_PART('week', TIMESTAMP '2022-10-31')"){code} > it will throws exception. > But if I use: > {code:java} > planner.parse("SELECT DATE_PART(week, TIMESTAMP '2022-10-31')"){code} > the parser works well. > > However, the former syntax, which is a quote-string, is correct according to > : [https://www.postgresql.org/docs/9.1/functions-datetime.html] > |Note that here the {{field}} parameter needs to be a string value, not a > name. The valid field names for {{date_part}} are the same as for > {{{}extract{}}}. > SELECT date_part('day', TIMESTAMP '2001-02-16 20:38:40');| > The first argument should be a quote string instead of a TimeUnit token. > -- This message was sent by Atlassian Jira (v8.20.10#820010)