Cross posting from SO: 
http://stackoverflow.com/questions/15293547/named-parameters-in-database-functions-with-sqlalchemy



I have a function in my database (Postgres) that looks like this:

create function test_f(a text default '*', b text default '+') returns text as 
$$
    select a || ' ' || b;$$ language sql;

Postgres allows calling it with named parameters:

mytest=> select test_f('a', 'b');                                           
test_f                                                                      
--------                                                                    
a b                                                                         (1 
row)                                                                     

mytest=> select test_f('a');                                                
test_f                                                                      
--------                                                                    
a +                                                                         (1 
row)                                                                     

mytest=> select test_f(b:='a');                                             
test_f                                                                      
--------                                                                    * a 
                                                                        (1 row) 
                                                                    

I want to do the same from Python, using SQLAlchemy's func 
construct<http://docs.sqlalchemy.org/en/rel_0_7/core/tutorial.html#functions>, 
but it seems thatfunc does not honor named parameters:

In [85]: print(sqlalchemy.func.test_f('a', 'b'))                            
test_f(:test_f_1, :test_f_2)                                                
In [86]: print(sqlalchemy.func.test_f('a'))                                 
test_f(:test_f_1)                                                           
In [87]: print(sqlalchemy.func.test_f(a='a'))                               
test_f()                                                                    

Am I missing something, or func does not support named parameters?

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to