Manlio Perillo wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi. > > I have written a small class in order to support PostgreSQL tsearch type: > > class TextSearchVector(UserDefinedType): > """Support for full-text search > See > http://www.postgresql.org/docs/8.4/static/datatype-textsearch.html > """ > > def get_col_spec(self): > return 'tsvector' > > > The problem with this code is that a string is converted to a tsearch > type without first normalizing it; this can also cause a syntax error. > > The solution is to use the `to_tsearch` function. > > In SQL (tested with PostgreSQL and SQLite, at least) I can do: > INSERT INTO test (text) values(to_tsvector('some text')); > > That is, it is possible to specify a scalar select statement for each > value. > > > Is this possible to do with SQLAlchemy? > > It seems to me that it is not possible. > It is not possible to specify an SQL scalar select statement in a custom > type bind_processor method, and it is not possible to specify an SQL > scalar select statement in an insert statement. > > Can this be solved using SQLAlchemy? > Or should I simply use triggers?
OK you mean SQL expression during compilation. This is ticket #1534 which is not yet implemented. Right now you'd have to set attributes to the to_tsvector() expression directly, note that the ORM and such accept SQL expressions as values. Which means if you're dealing just with ORM, you can use a @validates or similar (and maybe a comparator too) that wraps incoming values into to_tsvector(). The example in examples/postgis/postgis.py illustrates these techniques. > > > Thanks Manlio > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iEYEARECAAYFAktoc0IACgkQscQJ24LbaUQ/EgCeIKThU9dV8DZT0qampIR1iHRx > bP4AoI1/DPoEXRyewZGHLs6LF8DdCRZp > =YKtw > -----END PGP SIGNATURE----- > > -- > 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. > > -- 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.
