pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length)
Date: Tue, 28 Apr 2020 11:39:52 -0500
Message-ID: <8d6eface-4bde-b165-34f1-eeaefe88a6aa@gmail.com> (raw)
In-Reply-To: <c0149b4b-60d6-a1da-b068-05719d74a8dc@jakobs.com>
References: <CAOasRJYCUwMYdd=BL29TupW_iCbvM3YRM01YTB_WYSUEays3CA@mail.gmail.com>
	<CAExHW5vcOh-X-cz_Z=pWxqCi1Bm3FmGZz_UtxT+DFCg1PPaGmA@mail.gmail.com>
	<c0149b4b-60d6-a1da-b068-05719d74a8dc@jakobs.com>

An example:

test=# create table bargle (f1 varchar(10));
CREATE TABLE
test=# insert into bargle values ('01234567890123');
ERROR:  value too long for type character varying(10)


On 4/28/20 10:10 AM, Holger Jakobs wrote:
> Truncation will NEVER happen. PostgreSQL throws an ERROR on any attempt of 
> saving more characters (not bytes!) into a VARCHAR(50) column.
>
> There is some other well-known system which silently truncates, but we all 
> know why we would never use that.
>
> Am 28.04.20 um 13:46 schrieb Ashutosh Bapat:
>> On Tue, Apr 28, 2020 at 2:53 PM Rajin Raj <rajin.raj@opsveda.com> wrote:
>>> Is there any impact of using the character varying without providing the 
>>> length while creating tables?
>>> I have created two tables and inserted 1M records. But I don't see any 
>>> difference in pg_class. (size, relpage)
>>>
>>> create table test_1(name varchar);
>>> create table test_2(name varchar(50));
>> I don't think there's a difference in the way these two are stored
>> on-disk. But if you know that your strings will be at most 50
>> characters long, better set that limit so that server takes
>> appropriate action (i.e. truncates the strings to 50).
>>

-- 
Angular momentum makes the world go 'round.





view thread (22+ messages)  latest in thread

Message-ID: <8d6eface-4bde-b165-34f1-eeaefe88a6aa@gmail.com>
Permalink:  ../8d6eface-4bde-b165-34f1-eeaefe88a6aa@gmail.com/
Also on:    postgresql.org/message-id/8d6eface-4bde-b165-34f1-eeaefe88a6aa@gmail.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: ronljohnsonjr@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length)
  In-Reply-To: <8d6eface-4bde-b165-34f1-eeaefe88a6aa@gmail.com>

* 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