英文:
parsing using split_to_multimap without throwing an exception
问题
我想解析分配给变量的值,而不会引发异常:
例如,我想要这个返回3(它的确返回了)
select try_cast(array_join(element_at(split_to_multimap('a=3,b=5', ',', '='), 'a'), '') as int) as a
我希望这个返回NULL(不幸的是它引发了异常)
select try_cast(array_join(element_at(split_to_multimap('a=3Xb=5', ',', '='), 'a'), '') as int) as a
英文:
I want to parse out the values which are assigned to the variables without throwing exception:
e.g I want this to return 3 (which it does)
select try_cast(array_join(element_at(split_to_multimap('a=3,b=5', ',', '='), 'a'), '') as int) as a
I want this to return NULL (unfortunately it throws an exception)
select try_cast(array_join(element_at(split_to_multimap('a=3Xb=5', ',', '='), 'a'), '') as int) as a
答案1
得分: 1
你可以使用 try
:
通过返回 NULL 来评估表达式并处理某些类型的错误。
select try(
cast(
array_join(
element_at(
split_to_multimap('a=3Xb=5', ',', '='), 'a'), '') as int)) as a
英文:
You can use try
:
> Evaluate an expression and handle certain types of errors by returning NULL.
select try(
cast(
array_join(
element_at(
split_to_multimap('a=3Xb=5', ',', '='), 'a'), '') as int)) as a
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论