【问题标题】:Postgresql instr that works with unicode使用 unicode 的 Postgresql instr
【发布时间】:2013-08-08 23:14:10
【问题描述】:

我尝试在 postgresql 查询中执行 instr,然后意识到它似乎没有 instr 函数。

找到这个网址http://www.postgresql.org/docs/9.1/static/plpgsql-porting.html#PLPGSQL-PORTING-APPENDIX

展示了如何在 postgresql 的 plpgsql 语言中实现 instr。

但是它似乎不适用于 unicode varchar 列,因为我收到以下错误:

ERROR:  character with byte sequence 0xe4 0xb9 0xa6 in encoding "UTF8" has no equivalent in encoding "WIN1252"

虽然我用过

SET client_encoding = 'UTF8';

在我的客户端上。有人知道如何用 unicode 完成 instr 吗?

发现position 是相当于instr 的postgresql,但它给出的错误与上述相同。

这也不起作用:

select start from cnetd where substr(start, 6, 1) <> '/' and position('/' in convert(start, 'UTF8', 'LATIN1')) > 0 limit 90;

ERROR:  function convert(character varying, unknown, unknown) does not exist
LINE 1: ...re substr(start, 6, 1) <> '/' and position('/' in convert(st...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to
add explicit type casts.

【问题讨论】:

  • 错误消息表明您发送的 UTF-8 字符串无效,而不是该函数不适用于 UTF-8。它与函数本身无关。顺便说一句:Postgres 中还有一个 strpos 函数
  • 为什么 UTF8 字符串会无效?
  • 我如何识别违规行?
  • strpos 也报错

标签: postgresql-9.2


【解决方案1】:

原来我一定是辞职了,忘了做:

SET client_encoding = 'UTF8';

当我重新启动时。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-09
    • 2015-05-10
    • 2015-08-30
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    相关资源
    最近更新 更多