connection.create_function() is doing something very special that only applies to the pysqlite database, which has to do with the fact that the sqlite database engine is embedded in the Python interpreter, and that sqlite's embeddable library allows the caller to embed C functions into the SQL language. All other databases use a client/server model over TCP which does not allow for such a feature, meaning, a Python function in a particular python process can be invoked directly over a database connection, by the server. This might not be what you actually need, though.
Within the traditional client/server architecture, the Postgresql database also supports Python in order to write stored procedures, meaning, you can write a Python function and have it be invoked by the server with Postgresql, however, you would need to transmit the source code of the function over to the database, and not a Python code object which is what your in-process Python function actually is. There also may be many caveats to this system and I dont know anyone who has actually used it. It's documented at
https://www.postgresql.org/docs/current/plpython.html .
In the more general sense, that you want to create custom functions on the database, most databases support stored procedures and you normally write them using the stored procedure language provided by the database.
The SQLAlchemy Function construct comes into play when invoking these procedures, at least, when they are written so that they may be executed as inline-SQL functions (which is not always the case). If you construct a database-side procedure or function that can be invoked inline within a SQL statement, e.g. does not need something like SQL Server's "EXEC" in order to function, the "func." namespace can be used to render the name of the function as well as supply parameters to it, as in the examples at
https://docs.sqlalchemy.org/en/13/core/tutorial.html#functions .
basically pysqlite's create_function() is nifty but it does something that does not directly apply to client/server databases that are not embedded in the Python interpreter.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.