dbt SQL models do not bring any data from the database onto the worker that’s running dbt. Trying to do this in a SQL model isn’t really the right pattern - and you should understand when exactly your query will be executed because it may be surprising.
The simplest solution is to create your transformation as a UDF on the database using whatever features it provides for that (many cloud data warehouses support UDFs written in Python, JS, etc)