I need to store a URL in a PostgreSQL table. What is the best datatype for a field that will hold a URL with an undetermined length?
Thanks in advance.
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).
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.