Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SYSDATE Considered Identifier when used in inner select #3394

Closed
razvanb96 opened this issue Jan 22, 2022 · 3 comments · Fixed by #3396
Closed

SYSDATE Considered Identifier when used in inner select #3394

razvanb96 opened this issue Jan 22, 2022 · 3 comments · Fixed by #3396

Comments

@razvanb96
Copy link

razvanb96 commented Jan 22, 2022

Hi all,

I've been playing around with h2 v2.1.210 and observed quite an odd behaviour when having SYSDATE Keyword inside an inner select

Running SELECT SYSDATE FROM DUAL is going to work without any issues, but using sysdate inside an inner select is going to throw an error, because it seems like sysdate is expected to be an identifier.

SELECT * FROM (SELECT SYSDATE FROM DUAL) returns

Column "SYSDATE" not found; SQL statement: CREATE FORCE VIEW ( SELECT "SYSDATE" ) AS SELECT "SYSDATE" [42122-210]

@katzyn
Copy link
Contributor

katzyn commented Jan 23, 2022

Normally you should use CURRENT_DATE, CURRENT_TIMESTAMP, or LOCALTIMESTAMP in H2. They all have standard-compliant implementations and work as expected.

H2 should probably reject SYSDATE and all similar functions in all compatibility modes, with exception for Oracle compatibility mode in which it should be a keyword.

@katzyn
Copy link
Contributor

katzyn commented Jan 23, 2022

Hypothetically this issue can be fixed in a simpler way by preparation of inner query before reading of its execution plan for temporary view.

@razvanb96
Copy link
Author

razvanb96 commented Jan 23, 2022

Hi @katzyn I forgot to mention that indeed i am interested in using Oracle Compatibility Mode, as I am planing on using H2 for some Integration tests/ =fast Development Database, so changing the SYSDATE in the queries into CURRENT_TIMESTAMP is not exactly something that would work well in our System.

Thank you very much for you replay and PR. I checked my specific usecase against the code that you are propsing in there an it indeed fixes my problem. Waiting for it to get included in an offictial h2 release!

fp024 added a commit to fp024/spring-5-recipes-study that referenced this issue Apr 11, 2022
  - http://www.h2database.com/html/changelog.html
  - h2database/h2database#3394
    버전업 후, 테이블 생성 컬럼기본값으로 SYSDATE를 사용할때, 이것을 식별자로 간주되서
    테이블 생성이 실패하는 현상이 있었는데,
    이번 버전부터는 Oracle 호환성 모드를 설정하지 않는 이상 CURRENT_TIMESTAMP 또는 LOCALTIMESTAMP를
    써야한다고 한다.
    Oracle 호환 모드를 켜진 말고, CURRENT_TIMESTAMP 으로 바꾸자!

    그리고 h2의 버전업은 인스톨러를 통해 재설치하지 않고, jar만 교체했다.
    재설치할 필요없는 듯...😄😄😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants