【问题标题】:'Unicode' vs. 'String' with SQLAlchemy and PostgreSQL'Unicode' 与 'String' 与 SQLAlchemy 和 PostgreSQL
【发布时间】:2015-06-19 11:09:39
【问题描述】:

对于我缺乏有关字符编码的知识,我提前道歉。

我的问题是:在使用 SQLAlchemy(反之亦然)在 PostgreSQL 中存储数据时,使用 'Unicode' 类型而不是 'String' 类型是否有任何固有的优势/劣势?如果是这样,您介意详细说明吗?

【问题讨论】:

  • 我认为这是python2?
  • @CraigRinger Yessir。但是,您的询问也让我很好奇问题和答案与 python3 有何不同。
  • python3 对所有字符串表示使用 unicode,而 python2 没有。这会导致在字节字符串和 unicode 字符串之间转换的 python2 程序出现问题,而 Python3 程序通常可以避开这些问题。 python 文档有一个section 讨论这个问题。 This 也很好地阅读了 python2 中 unicode 的挫败感。尽管有烦恼,但最好使用 unicode,因为它似乎是面向未来的方向。
  • 我认为问题是关于 sqlalchemy.Unicode 列类型与 sqlalchemy.String 列类型。与标准的 python unicode/string 类型无关,其中已经写了很多。

标签: python postgresql unicode sqlalchemy python-2.x


【解决方案1】:

在 99.99% 的情况下,都使用 Unicode,如果可能,请使用 Python 3,因为它会让您的生活更轻松。

【讨论】:

  • 能否详细说明原因?
猜你喜欢
  • 2012-10-15
  • 1970-01-01
  • 2020-01-21
  • 2012-08-05
  • 1970-01-01
  • 1970-01-01
  • 2012-03-10
  • 1970-01-01
  • 2018-06-23
相关资源
最近更新 更多