Skip to content

Commit

Permalink
Fix PostgreSQL and openGauss time extract function parse week and qua…
Browse files Browse the repository at this point in the history
…rter error (#33564)

* Fix PostgreSQL time extract function parse week and quarter error

* Fix openGauss time extract function parse week and quarter error

* Support time extract function parse week and quarter in openGauss

* Added support for time extract function parse week and quarter in PostgreSQL and openGauss
  • Loading branch information
lcfliuxi authored Nov 8, 2024
1 parent 2f8aebb commit 5c70cc5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ unreservedWord
| PROCEDURES
| PROGRAM
| PUBLICATION
| QUARTER
| QUOTE
| RANGE
| READ
Expand Down Expand Up @@ -427,6 +428,7 @@ unreservedWord
| VIEW
| VIEWS
| VOLATILE
| WEEK
| WHITESPACE
| WITHIN
| WITHOUT
Expand Down Expand Up @@ -1147,7 +1149,9 @@ extractList

extractArg
: YEAR
| QUARTER
| MONTH
| WEEK
| DAY
| HOUR
| MINUTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ unreservedWord
| PROCEDURES
| PROGRAM
| PUBLICATION
| QUARTER
| QUOTE
| RANGE
| READ
Expand Down Expand Up @@ -428,6 +429,7 @@ unreservedWord
| VIEW
| VIEWS
| VOLATILE
| WEEK
| WHITESPACE
| WITHIN
| WITHOUT
Expand Down Expand Up @@ -1114,7 +1116,9 @@ extractList

extractArg
: YEAR
| QUARTER
| MONTH
| WEEK
| DAY
| HOUR
| MINUTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,50 @@
</projections>
</select>

<select sql-case-id="select_extract_function_week">
<projections start-index="7" stop-index="56">
<expression-projection text="EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40')" start-index="7" stop-index="56">
<expr>
<function function-name="EXTRACT" start-index="7" stop-index="56" text="EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40')">
<parameter>
<extract-arg start-index="15" stop-index="18" text="WEEK" />
</parameter>
<parameter>
<type-cast-expression>
<expression>
<literal-expression value="2001-02-16 20:38:40" start-index="35" stop-index="55" />
</expression>
<data-type>TIMESTAMP</data-type>
</type-cast-expression>
</parameter>
</function>
</expr>
</expression-projection>
</projections>
</select>

<select sql-case-id="select_extract_function_quarter">
<projections start-index="7" stop-index="59">
<expression-projection text="EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40')" start-index="7" stop-index="59">
<expr>
<function function-name="EXTRACT" start-index="7" stop-index="59" text="EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40')">
<parameter>
<extract-arg start-index="15" stop-index="21" text="QUARTER" />
</parameter>
<parameter>
<type-cast-expression>
<expression>
<literal-expression value="2001-02-16 20:38:40" start-index="38" stop-index="58" />
</expression>
<data-type>TIMESTAMP</data-type>
</type-cast-expression>
</parameter>
</function>
</expr>
</expression-projection>
</projections>
</select>

<select sql-case-id="select_extract_function_for_oracle">
<projections start-index="7" stop-index="56" literal-start-index="7" literal-stop-index="56">
<expression-projection text="EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40')" start-index="7" stop-index="56" literal-start-index="7" literal-stop-index="56">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<sql-case id="select_values" value="SELECT VALUES(order_id) FROM t_order" db-types="MySQL" />
<sql-case id="select_current_user_brackets" value="SELECT CURRENT_USER()" db-types="MySQL" />
<sql-case id="select_extract_function" value="SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40')" db-types="PostgreSQL,openGauss" />
<sql-case id="select_extract_function_week" value="SELECT EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40')" db-types="PostgreSQL,openGauss" />
<sql-case id="select_extract_function_quarter" value="SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40')" db-types="PostgreSQL,openGauss" />
<sql-case id="select_extract_function_for_oracle" value="SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL" db-types="Oracle" />
<sql-case id="select_mod_function" value="SELECT MOD(order_id, 1) from t_order" db-types="PostgreSQL,openGauss" />
<sql-case id="select_sys_xml_agg" value="SELECT SYS_XMLAGG(SYS_XMLGEN(last_name)) XMLAGG FROM employees WHERE last_name LIKE 'R%' ORDER BY xmlagg;" db-types="Oracle" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@
<sql-case id="unsupported_select_case_for_opengauss_438" value="select B'101' | as result;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_439" value="select B'101' # as result;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_440" value="select B'11110' # B'0000';" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_443" value="select extract(quarter from timestamp '2001-02-16 20:38:40') from sys_dummy;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_444" value="select extract(week from timestamp '2001-02-16 20:38:40') from sys_dummy;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_447" value="select atan(11 11) from sys_dummy;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_448" value="select atan(,) from sys_dummy;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_451" value="select $$the lexeme ' ' , contains spaces$$::tsvector@@ ','::tsquery as result;" db-types="openGauss" />
Expand Down

0 comments on commit 5c70cc5

Please sign in to comment.