Postgresql操作符类“varchar_pattern_ops”不接受数据类型整数 [英] Postgresql operator class "varchar_pattern_ops" does not accept data type integer

查看:1167
本文介绍了Postgresql操作符类“varchar_pattern_ops”不接受数据类型整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的数据id postgresql从字符串迁移到django中的整数,以便在sphinx搜索中使用它们。所以首先我正在进行数据迁移,将数据转换为字符串的整数,如下所示。

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);

喜欢被告知这里

但我收到错误


错误:操作符类varchar_pattern_ops不接受数据类型整数

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

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

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

此错误发生在South和pgAdmin中。数据是正确的 - 字符串类型为空或整数。我做错了什么?

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?

推荐答案

我只能复制你的错误信息,如:

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

相关文档:

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

这篇关于Postgresql操作符类“varchar_pattern_ops”不接受数据类型整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆