pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Durgamahesh Manne <maheshpostgres9@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general@lists.postgresql.org
Cc: andreas@a-kretschmer.de
Subject: Re: Regarding varchar max length in postgres
Date: Mon, 15 Oct 2018 10:24:23 -0400
Message-ID: <9907.1539613463@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJCZkoJN-vAZLOU1XHxVjCfh1UYtJvup958wRph+upxP9wkj3w@mail.gmail.com>
References: <CAJCZkoLyv+0J0ACodg+mjL=VXFBMrMKZWWXkwMGgUFkOz8byBw@mail.gmail.com>
	<a9d74f73-12a4-9b06-3ab3-1ff0bfeab01b@aklaver.com>
	<CAJCZkoKaRr3uR+w0+W91N7zmv9XcVmTKjZ0hCMg61s7VxcvkdA@mail.gmail.com>
	<CAJCZkoKPAeT7G9B0oqJ7pH=PEyeeS6bviDmUyMsjgsAtKdDw+g@mail.gmail.com>
	<CAJCZkoKsYP6L91Rd3=8oxRh6K_GKZAFkmd1--PR4JWzqop_HSQ@mail.gmail.com>
	<CAJCZkoJN-vAZLOU1XHxVjCfh1UYtJvup958wRph+upxP9wkj3w@mail.gmail.com>

Durgamahesh Manne <maheshpostgres9@gmail.com> writes:
>>> If character varying is used without length specifier, the type
>>> accepts strings of any size
>>> but varchar does not accept more than this 10485760 value

You're confusing the size of string that can be stored with the
largest value accepted for "n" in "varchar(n)".  This is documented,
in the same place that people have been pointing you to:

    In any case, the longest possible character string that can be stored
    is about 1 GB. (The maximum value that will be allowed for n in the
                    ---------------------------------------------------
    data type declaration is less than that. It wouldn't be useful to
    ----------------------------------------
    change this because with multibyte character encodings the number of
    characters and bytes can be quite different. If you desire to store
    long strings with no specific upper limit, use text or character
    varying without a length specifier, rather than making up an arbitrary
    length limit.)

As you found out, the limit for "n" is ~ 10 million.

In principle, we could have allowed it to be as much as 1Gb divided by
the maximum character length of the database's encoding, but it did
not seem like a great idea for the limit to be encoding-dependent.

As the last sentence in the doc paragraph points out, the preferred
thing to do if you just want to allow very long strings is to leave
off "(n)" altogether.

The subtext here, which maybe we ought to state in a more in-your-face
way, is that if you use char(N) or varchar(N) without a concrete
application-driven reason why N has to be that particular value,
no more or less, then You're Doing It Wrong.  Artificially-chosen
column width limits are a bad idea left over from the days of
punched cards.  The reason the limit on N is much smaller than it
could theoretically be is that column declarations with very large
N are, without exception, violations of this principle.

			regards, tom lane




view thread (17+ messages)  latest in thread

Message-ID: <9907.1539613463@sss.pgh.pa.us>
Permalink:  ../9907.1539613463@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9907.1539613463@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, maheshpostgres9@gmail.com, adrian.klaver@aklaver.com, andreas@a-kretschmer.de
  Subject: Re: Regarding varchar max length in postgres
  In-Reply-To: <9907.1539613463@sss.pgh.pa.us>
  References: <CAJCZkoLyv+0J0ACodg+mjL=VXFBMrMKZWWXkwMGgUFkOz8byBw@mail.gmail.com> <a9d74f73-12a4-9b06-3ab3-1ff0bfeab01b@aklaver.com> <CAJCZkoKaRr3uR+w0+W91N7zmv9XcVmTKjZ0hCMg61s7VxcvkdA@mail.gmail.com> <CAJCZkoKPAeT7G9B0oqJ7pH=PEyeeS6bviDmUyMsjgsAtKdDw+g@mail.gmail.com> <CAJCZkoKsYP6L91Rd3=8oxRh6K_GKZAFkmd1--PR4JWzqop_HSQ@mail.gmail.com> <CAJCZkoJN-vAZLOU1XHxVjCfh1UYtJvup958wRph+upxP9wkj3w@mail.gmail.com> <9907.1539613463@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox