On Sep 3, 11:55 am, Michael Bayer <[EMAIL PROTECTED]> wrote:
> 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
Using literal_column worked--thanks! I had tried earlier, when I
couldn't get literal() working, but I hadn't tried setting the type_
to String. In this case, at least, it is necessary--without it, it
uses + instead of || outside of the first set of parens, which chokes
postgres.
I'm still not clear on how to get it working using literal(), but
that's fine, as this works great.
Thanks yet again,
Jeff
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---