Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…branch/tsvector into tsvector
  • Loading branch information
zzzeek committed Dec 10, 2013
2 parents 111c615 + d3b65cd commit d5a86d8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 3 additions & 1 deletion doc/build/dialects/postgresql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect::
DOUBLE_PRECISION, ENUM, FLOAT, HSTORE, INET, INTEGER, \
INTERVAL, MACADDR, NUMERIC, REAL, SMALLINT, TEXT, TIME, \
TIMESTAMP, UUID, VARCHAR, INT4RANGE, INT8RANGE, NUMRANGE, \
DATERANGE, TSRANGE, TSTZRANGE
DATERANGE, TSRANGE, TSTZRANGE, TSVECTOR

Types which are specific to PostgreSQL, or have PostgreSQL-specific
construction arguments, are as follows:
Expand Down Expand Up @@ -77,6 +77,8 @@ construction arguments, are as follows:
.. autoclass:: REAL
:members: __init__

.. autoclass:: TSVECTOR
:members: __init__

.. autoclass:: UUID
:members: __init__
Expand Down
5 changes: 3 additions & 2 deletions lib/sqlalchemy/dialects/postgresql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from .base import \
INTEGER, BIGINT, SMALLINT, VARCHAR, CHAR, TEXT, NUMERIC, FLOAT, REAL, \
INET, CIDR, UUID, BIT, MACADDR, DOUBLE_PRECISION, TIMESTAMP, TIME, \
DATE, BYTEA, BOOLEAN, INTERVAL, ARRAY, ENUM, dialect, array, Any, All
DATE, BYTEA, BOOLEAN, INTERVAL, ARRAY, ENUM, dialect, array, Any, All, \
TSVECTOR
from .constraints import ExcludeConstraint
from .hstore import HSTORE, hstore
from .ranges import INT4RANGE, INT8RANGE, NUMRANGE, DATERANGE, TSRANGE, \
Expand All @@ -23,5 +24,5 @@
'DOUBLE_PRECISION', 'TIMESTAMP', 'TIME', 'DATE', 'BYTEA', 'BOOLEAN',
'INTERVAL', 'ARRAY', 'ENUM', 'dialect', 'Any', 'All', 'array', 'HSTORE',
'hstore', 'INT4RANGE', 'INT8RANGE', 'NUMRANGE', 'DATERANGE',
'TSRANGE', 'TSTZRANGE'
'TSRANGE', 'TSTZRANGE', 'TSVECTOR'
)
33 changes: 33 additions & 0 deletions lib/sqlalchemy/dialects/postgresql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,35 @@ def process(value):

PGUuid = UUID

class TSVECTOR(sqltypes.TypeEngine):
"""The TSVECTOR type implements the Postgresql text search type
TSVECTOR.
It can be used to do full text queries on natural language
*documents*.
Search queries are performed using the ``@@`` operator in
postgresql. This is made available with the ``match`` method
available on the column.
This means that if you have a table ``Example`` with a column
``text`` of type ``TSVECTOR``, you can create a search clause like
so
::
Example.text.match("search string")
which will be compiled to
::
text @@ to_tsquery('search string')
"""
__visit_name__ = 'TSVECTOR'



class _Slice(expression.ColumnElement):
__visit_name__ = 'slice'
Expand Down Expand Up @@ -913,6 +942,7 @@ def _on_metadata_drop(self, target, bind, checkfirst, **kw):
'interval': INTERVAL,
'interval year to month': INTERVAL,
'interval day to second': INTERVAL,
'tsvector' : TSVECTOR
}


Expand Down Expand Up @@ -1163,6 +1193,9 @@ def visit_exclude_constraint(self, constraint):


class PGTypeCompiler(compiler.GenericTypeCompiler):
def visit_TSVECTOR(self, type):
return "TSVECTOR"

def visit_INET(self, type_):
return "INET"

Expand Down
3 changes: 2 additions & 1 deletion test/dialect/postgresql/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ def get_col_spec(self):
Column('plain_interval', postgresql.INTERVAL),
Column('year_interval', y2m()),
Column('month_interval', d2s()),
Column('precision_interval', postgresql.INTERVAL(precision=3))
Column('precision_interval', postgresql.INTERVAL(precision=3)),
Column('tsvector_document', postgresql.TSVECTOR)
)

metadata.create_all()
Expand Down

0 comments on commit d5a86d8

Please sign in to comment.