TRY_CONVERT
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
TRY_CONVERT('42'::text, NULL::int2) -- returns 42::int2
TRY_CONVERT('42d'::text, NULL::int2) -- returns NULL::int2
TRY_CONVERT('42d'::text, 1234::int2) -- returns 1234::int2
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.sql or use select add_type_for_try_convert('date'::regtype); to add types.
In init we can add all supported types, but with add_type_for_try_convert user can add whatever type he wants
ERROR HANDLING
Error handles by PG_TRY() PG_CATCH()
But better way is use "soft" error handling from Postgres 17 (https://github.com/postgres/postgres/commit/ccff2d20ed9622815df2a7deffce8a7b14830965) it also realising OPENGPDB (https://github.com/open-gpdb/gpdb/commit/21be3688729ec4468ffd083da197721860fa2cbd). Of course it needs to convert datatype function to support "soft" error handling
Fixes #ISSUE_Number
What does this PR do?
Type of Change
- [ ] Bug fix (non-breaking change)
- [ ] New feature (non-breaking change)
- [ ] Breaking change (fix or feature with breaking changes)
- [ ] Documentation update
Breaking Changes
Test Plan
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Passed
make installcheck - [ ] Passed
make -C src/test installcheck-cbdb-parallel
Impact
Performance:
User-facing changes:
Dependencies:
Checklist
- [ ] Followed contribution guide
- [ ] Added/updated documentation
- [ ] Reviewed code for security implications
- [ ] Requested review from cloudberry committers
Additional Context
CI Skip Instructions
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.