String field length in Postgres SQL

后端 未结 3 2035
半阙折子戏
半阙折子戏 2021-01-15 04:55

I have a string filed in an SQL database, representing a url. Some url\'s are short, and some very long. I don\'t really know waht\'s the longest URL I might encounter, so t

3条回答
  •  悲&欢浪女
    2021-01-15 05:43

    Usually database storage engines can do many thing you don't expect. But basically, there are two kinds of text fields, that give a hint what will go on internally.

    char and varchar. Char will give you a fixed field column and depending on the options in the sql session, you may receive space filled strings or not. Varchar is for text fields up to a certain maximum length.

    Varchar fields can be stored as a pointer outside the block, so that the block keeps a predictable size on queries - but that is an implementation detail and may vary from db to db.

提交回复
热议问题