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

TRY_CONVERT #901

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

TRY_CONVERT #901

wants to merge 2 commits into from

Conversation

robozmey
Copy link

@robozmey robozmey commented Feb 3, 2025

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 (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

  • 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

Additional Context

CI Skip Instructions


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 this pull request may close these issues.

1 participant