CREATE OR REPLACE FUNCTION public.get_product_price()
RETURNS numeric AS
$BODY$
BEGIN
return 100;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
CREATE OR REPLACE FUNCTION public.get_product_price(product products)
RETURNS numeric AS
$BODY$
-- do something with product
BEGIN
return 100;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
--SQLAlchemy -The Python SQL Toolkit and Object Relational MapperTo post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.---You received this message because you are subscribed to the Google Groups "sqlalchemy" group.To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/071cec63-88d8-4660-bfe0-e5317924493e%40googlegroups.com.
SELECT *, get_product_price(products) FROM products;
HiFirst thank you for your reply.@Mike, yes. I wish to pass the row products row. I'm attaching working SQLSELECT *, get_product_price(products) FROM products;This works great in postgres. I tried it also on Mysql but they support only scalar values. I suspect that might work with other databases. I don't need to pass any dynamic arguments to column_property, it just needs to reference to existing row. I'll try with hybrid and let you know.
@JonathanYes, if I pass the ID it works great. I'm just worried about the performance. If I want to execute then function in huge SELECT, I would need to do reselect on each row.On Saturday, 16 May 2020 21:42:54 UTC+2, Jonathan Vanasco wrote:It’s been a while since I’ve worked on stuff like this, but IIRC the simplest way was to use a function that accepts an ID and to flush in SqlAlchemy before executing it. Then you select the necessary row fields within the sql function, instead of passing args in or trying to pass a row in.In my experience, when you pass multiple args in, the function becomes very fragile and prone to break as your model changes.
--SQLAlchemy -The Python SQL Toolkit and Object Relational MapperTo post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.---You received this message because you are subscribed to the Google Groups "sqlalchemy" group.To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/fa2e6ac5-22ed-4448-8228-b29a11682975%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlal...@googlegroups.com.