On 23.04.2010, at 17:03, Michael Bayer wrote:


On Apr 23, 2010, at 9:59 AM, Paul Balomiri <paulbalom...@gmail.com> wrote:

Hi,

Thanks, for your reply. I was aware that it is not just a string substitution,
and that the bindparams also maps the type of the parameters e.t.c.

But is it possible to supply a type /set of types which are or represent a lexical sub-structure ? I might go into doing it, but first i want to check that i'm not reinventing the wheel.

I noticed that the where clause can be supplied several times, so
select( [my_table_metadata]). where(....). where(...) is valid, thus it is possible for this special case to insert a logical expression after the initial select() definition.

I am looking for a similar, but more general case, not necessarily using bindparam where func.now() would be a valid substitution or insertion element into a preexisting expression.


Why not just create a python function that generatively produces the desired statement based on arguments? I don't see the advantage to something more magical than that.
Well, this is what i already do:

lazy_sql_partial = functools.partial(lambda x: select([...] , from_obj(func.a(bindparam('a'),bindparam('b'),x ))) )
and then i name the binding like so:
lazy_sql_unbound = (lazy_sql_partial, ("funcarg"))


At the time when i generate the sql expression I do not know the parameters, not even a default. Those are generated based on user input. in case parameters are missing for a whole expression the whole expression is skipped.

A even simpler expression would be a=1 or a=2 or ....... At the moment i cannot generate such a constuct, which allows me to define a select in one place, and then later add a or_(1,2,...) clause at a certain point.As a special case i could use select().where(1). where(2)... to get an and_(1,2,...)


An example :
Whenever the map window changes, i need to calculate the dataset which falls out of the current window, and the ones which drops in. Additionally i want to query the a modified sql expression whenever the table changes (modified = with an additional in_ costraining to pks in the table)
to do both i need to regenerate parts of the sql, but not all of it.

The way i do it now seems rather ugly because:
1) (partial_bound_func, ("funcarg")) is error prone ( I know i cold do more reflection to find out argument numbers and names , but it would in the end duplicate the bindparam mechanism )
2) to execute i have to:
- first look for parameters which are arguments to the partial generative functions myselect= lazy_sql_unbound( user input params for partial )
        - then use the remaining parameters in session.execute( )

It just feels like all of this rather belongs into the lib, because it could be all solved by allowing bindparam to have a value of type SQLExpression.
moreover, the expression substitutions could accept bindparams as well.

As a last point , the compiler could check the validity, as it does already.







regards
Paul Balomiri
paulbalom...@gmail.com



On 23.04.2010, at 15:26, Michael Bayer wrote:


On Apr 23, 2010, at 6:58 AM, Paul Balomiri wrote:

Hi,

Several days ago i has a similar question, which
was, perhaps a bit too theoretical. Here is a simple case:

select(text(select * from f(:time)) )

can I supply alternatively either
{time: datetime.datetime(1999,9,9,9,9,9)}
or
{time: " now()"}
I cannot get around that sqlalchemy interprets " now()" as a string, while i try to use the postgres(or other backends) now() function.

bind parameters exist only for the purpose of specifying literal data to be injected as the values into a SQL statement. They cannot be used to modify the lexical structure of a statement. So a lexical unit like "CURRENT TIMESTAMP" or "NOW()" is part of the statement's lexical source and cannot be injected as a bind parameter.

To put it another way, bind parameters are not just string substitutions the way something like "foo %s" % ('bar') is in Python, even though they may look that way.


--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en .


--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en .


--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en .


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to