Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql operator class "varchar_pattern_ops" does not accept data type integer

I'm trying migrate my data id postgresql from string to integers in django to use them in sphinx search. So first of all I'm making data migration, converting my data to integers in string like this

db.execute('''UPDATE the_table SET foo='1' WHERE foo='bar';''')

Then I'm making schema migration

ALTER TABLE the_table ALTER COLUMN col_name TYPE integer USING (col_name::integer);

like it was told here

But I'm getting an error

ERROR: operator class "varchar_pattern_ops" does not accept data type integer

SQL-состояние: 42804

This error occurs both in South and pgAdmin. The data is correct - it is Null or integer in string type. What am I doing wrong?

like image 809
FeroxTL Avatar asked Nov 29 '13 11:11

FeroxTL


People also ask

What is operator class in Postgres?

An operator class defines how a particular data type can be used with an index. The operator class specifies that certain operators will fill particular roles or “strategies” for this data type and this index method.

What is Varchar_pattern_ops?

The varchar_pattern_ops improves the performance of like queries by 4 times i.e 4x. For example, lets have this like query on name column (that has sequential index.) Select * from users where name like 'John%' We might have added a regular Rails index in migration for this name column as.

What is operator class in index postgresql?

The operator class identifies the operators to be used by the index for that column. For example, a B-tree index on the type int4 would use the int4_ops class; this operator class includes comparison functions for values of type int4 .


1 Answers

I'm only able to reproduce your error message like so:

denis=# create index test_idx on test (val varchar_pattern_ops);
CREATE INDEX
denis=# alter table test alter val type int using (val::int);
ERROR:  operator class "varchar_pattern_ops" does not accept data type integer

If you've a funky index like that, try dropping and recreating it like so:

denis=# drop index test_idx;
DROP INDEX
denis=# create index test_idx on test (val);
CREATE INDEX
denis=# alter table test alter val type int using (val::int);
ALTER TABLE

Related docs:

http://www.postgresql.org/docs/current/static/indexes-opclass.html

like image 132
Denis de Bernardy Avatar answered Oct 14 '22 04:10

Denis de Bernardy