PostgreSQL 中 URL 的数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41633436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Datatype for a URL in PostgreSQL
提问by Jeena Rita
I need to store a URLin a PostgreSQLtable. What is the best datatype for a field that will hold a URL with an undetermined length?
我需要在PostgreSQL表中存储一个URL。将保存不确定长度的 URL 的字段的最佳数据类型是什么?
Thanks in advance.
提前致谢。
回答by Fabian Pijcke
The answer depends on what you intend to do with the data.
答案取决于您打算对数据做什么。
If you just need to store some uris in order to print them when requested, the text datatype seems indicated. There seems to be no standard about the maximum length of an url (note that browsers have their own limits, for example at least some years ago IE was limited to 2083 characters, but this is unrelated to our problem).
如果您只需要存储一些 uri 以便在请求时打印它们,则似乎指示了文本数据类型。似乎没有关于 url 的最大长度的标准(请注意,浏览器有自己的限制,例如至少几年前 IE 被限制为 2083 个字符,但这与我们的问题无关)。
If you need some advanced operations on uris (for example, computing the base uri or extract some other parts), then you may want to use some libraries designed for this purpose. One example of such library (actually I know of no alternative) is pguri.
如果您需要对 uri 进行一些高级操作(例如,计算基本 uri 或提取其他一些部分),那么您可能需要使用一些为此目的而设计的库。这种库的一个例子(实际上我知道别无选择)是pguri。