TRY_CONVERT#901
Conversation
| if (OidIsValid(sourceTypeId)) | ||
| sourceTypeId = getBaseType(sourceTypeId); | ||
| if (OidIsValid(targetTypeId)) | ||
| targetTypeId = getBaseType(targetTypeId); |
There was a problem hiding this comment.
What if the source or target type is invalid?
There was a problem hiding this comment.
All will happend like in
cloudberry/src/backend/parser/parse_coerce.c
Line 3151 in e601fb6
We will look in pg_cast table - will find nothing, will try to get TypeCategory and will get assert in TypeCategory(targetTypeId)
|
|
||
| *funcId = castForm->castfunc; | ||
| ReleaseSysCache(tuple); | ||
| } |
There was a problem hiding this comment.
Better add else branch here.
| } | ||
|
|
||
| Datum | ||
| convert_from_function(Datum value, int32 typmod, Oid funcId, bool *is_failed) |
There was a problem hiding this comment.
Why is the error handling undetermined?
7c1d1e5 to
c3b4c2b
Compare
737228d to
fde465f
Compare
* Add README for try_convert extension
| @@ -0,0 +1,92 @@ | |||
| # TRY_CONVERT | |||
|
|
|||
| TRY_CONVERT is Greenplum extension, which adds function for error-safe type cast like [TRY_CAST from SQL-Server](https://learn.microsoft.com/ru-ru/sql/t-sql/functions/try-cast-transact-sql?view=sql-server-ver16) | |||
There was a problem hiding this comment.
| TRY_CONVERT is Greenplum extension, which adds function for error-safe type cast like [TRY_CAST from SQL-Server](https://learn.microsoft.com/ru-ru/sql/t-sql/functions/try-cast-transact-sql?view=sql-server-ver16) | |
| TRY_CONVERT is Greenplum/Cloudberry extension, which adds function for error-safe type cast like [TRY_CAST from SQL-Server](https://learn.microsoft.com/ru-ru/sql/t-sql/functions/try-cast-transact-sql?view=sql-server-ver16) |
|
|
||
| ## Why signature is so strange? | ||
|
|
||
| Greenplum function polymorphism accept to have polymorphic functions only one any type in signature. |
There was a problem hiding this comment.
| Greenplum function polymorphism accept to have polymorphic functions only one any type in signature. | |
| Greenplum/Cloudberry function polymorphism accept to have polymorphic functions only one any type in signature. |
|
Hi @robozmey thanks for your updates! Now the license headers look good to me. Please make sure these files are originally created by our community members, not cherry-picked or copied from other projects. Before merging, welcome to squash your commits into one and revise the commit message body, you can take this template as a reference. |
Extension TRY_CONVERT adds function TRY_CONVERT
TRY_CONVERT was made to use like TRY_CAST from SQL-Server
Due polymorphism have strange signature (some_type, anyelement) -> anyelement
First parament is SOURCE_VALUE
Second parameter is DEFAULT_VALUE::TARGET_TYPE
We cannot have (any1, any2) -> any2 signature with different anyelement types, but we can create multiple (_, any) -> any functions in
contrib/try_convert/try_convert--1.0.sqlor useselect add_type_for_try_convert('date'::regtype);to add types.In init we can add all supported types, but with
add_type_for_try_convertuser can add whatever type he wantsERROR HANDLING
Error handles by PG_TRY() PG_CATCH()
But better way is use "soft" error handling from Postgres 17 (postgres/postgres@ccff2d2) it also realising OPENGPDB (open-gpdb/gpdb@21be368). Of course it needs to convert datatype function to support "soft" error handling
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions