If you are using SQL Server, that is theoretically possible (though I have
never tried it) by using the .NET extensibility of SQL Server. Iron Python
is a .NET native version of Python that you could theoretically embed in
SQL Server and with a little bit of C# glue code have it run your Python
function on every row in the query.
Without details about what it is your function does and why you think it
would be better to run it in SQL Server, I question the usefulness of
trying to do this. Is it to limit the amount of data that gets sent
(because you create some kind of aggregate) or is this just a "hey neat I
can do that" kind of a question?
For what it is worth, PostgreSQL has the ability to run python functions
though embedding of a CPython interpreter, though I can't remember what it