You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I create a PG function helper like this (a wrapper to xpath function that returns only the first element from the resulting array, and returns NULL for no results):
createfunctionmaster_dbo.my_xpath_first(expr sys.nvarchar, doc xml, ns sys.nvarchar)
returns xml as $$
with cte(arr) as (select xpath(expr::text, doc, ns::text[][]))
select
case when array_length(arr, 1) >0
then arr[1]
else null
end
from cte
$$ language sql immutable
But it breaks when CTE is used in T-SQL like this:
with items_cte (item) as (
select unnest(xpath('//a:item', cast('<root xmlns="ns1"> <item id="41"/> <item/> <item id="43"/></root> 'asxml), '{{a, ns1}}'))
as item
)
select
my_xpath_first('/a:item/@id', item, '{{a, ns1}}') as id
from items_cte
Msg 33557097, Level 16, State 1, Line 10
zero-length delimited identifier at or near "[]"
There is a workaround to use language plpgsql instead of language sql, but I assume that SQL function is supposed to work too.
Version
BABEL_4_X_DEV (Default)
Extension
babelfishpg_tsql (Default)
Which flavor of Linux are you using when you see the bug?
Fedora
Relevant log output
No response
Code of Conduct
I agree to follow this project's Code of Conduct.
The text was updated successfully, but these errors were encountered:
What happened?
If I create a PG function helper like this (a wrapper to xpath function that returns only the first element from the resulting array, and returns
NULL
for no results):It works from T-SQL in simple examples:
But it breaks when CTE is used in T-SQL like this:
There is a workaround to use
language plpgsql
instead oflanguage sql
, but I assume that SQL function is supposed to work too.Version
BABEL_4_X_DEV (Default)
Extension
babelfishpg_tsql (Default)
Which flavor of Linux are you using when you see the bug?
Fedora
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: