V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
pxiphx891
V2EX  ›  问与答

postgresql 的 text 类型是不是很方便

  •  
  •   pxiphx891 · 229 天前 · 840 次点击
    这是一个创建于 229 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我公司用的是 mysql ,我自己使用过 postgresql ,我感觉日常使用上,这两个没有什么不同。但是对我来说,postgres 有一个优势:它的 text 类型不需要指定长度,而且根据这个文档

    There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.

    这个不需要指定长度的类型更被推荐使用。 我平时创建的表,大部分字段其实都是字符串类型,不用思考这个字段有多长,这不是一件非常方便的事情吗?为什么新项目选型的时候,大家还要用 mysql 呢

    5 条回复    2023-09-13 10:41:19 +08:00
    zzzkkk
        1
    zzzkkk  
       229 天前
    postsql 太严密了 groupby 时好像每个字段都要出现在 select 里面
    我现在还把 mysql 的 sql_mode 置空
    lanlanye
        2
    lanlanye  
       229 天前 via iPhone
    可能是习惯吧……我是觉得 pg 好用很多
    des
        3
    des  
       229 天前 via iPhone
    @zzzkkk 也就低版本 mysql 这样了
    newaccount
        4
    newaccount  
       229 天前
    因为 ilike 才不区分大小写、因为 collation 配置、因为 MySQL 可以无脑覆盖升级、因为其他人对这个数据库的熟悉程序

    自己用当然怎么爽怎么来;团队里使用,还是得选择更傻瓜无脑式的,毕竟总有人变着花儿的弄点幺蛾子出来
    troywinter
        5
    troywinter  
       228 天前
    pg 的优点远不止这些,多样的扩展类型对很多复杂业务有很好的支持,最近七八年工作的几家公司都在用 pg ,性能确实非常稳定
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5375 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 09:26 · PVG 17:26 · LAX 02:26 · JFK 05:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.