On Sep 3, 2008, at 11:09 AM, Jeff wrote:

>>
>> in general, text() is intended primarily for fully constructed SQL
>> statements, and does not implement the semantics of an element used
>> within an expression.  For individual literal components, use the
>> literal() function which produces a bind parameter, which will have
>> all the semantic properties of any other column-oriented expression
>> element.  if that doesn't resolve your issue we can try again with
>> something more concrete.
>
> Michael,
>
> Thanks, as usual, for the help.  Sorry I didn't respond earlier--I was
> on vacation.  I tried what you suggested, but I couldn't figure out
> how to apply it properly.  If I just change the line:
> yield sql.text(" ' ' ")
> to:
> yield sql.literal(" ' ' ")
> then it requires that I pass in parameters when I actually run the
> query--which is kind of silly in this case.

well, bind params are used but you dont have to "pass" them in  
explicitly, the compiled statement has their values built in.  this is  
the default behavior so that quotes and such are properly escaped.

> I think I should explain better what I'm trying to do with that
> generator, as it's a bit weird.  I need a string like this:
> table.col1 || ' ' || table.col2 || ' ' || table.col3
> which I can then pass to posgres's to_tsvector() (via sql.func).  The
> extra spaces are necessary for the full-text search to work properly.

if you dont want the binds to be used, say:

  func._tsvector(t.c.col1 + literal_column("' '", type_=String) +  
t.c.col2 + literal_column("' '", type_=String) + t.c.col3)

the type_=String is not strictly needed but allows the precedence  
rules to prevent a bunch of unnecessary parens


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to