Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length)

From: Holger Jakobs <holger(at)jakobs(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length)
Date: 2020-04-28 15:10:31
Message-ID: c0149b4b-60d6-a1da-b068-05719d74a8dc@jakobs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-hackers

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(dot)raj(at)opsveda(dot)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).
>
--
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Paul Carlucci 2020-04-28 16:24:23 Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length)
Previous Message Ashok kumar Mani 2020-04-28 12:53:12 RE: failover database replication failing!

Browse pgsql-hackers by date

  From Date Subject
Next Message Jonah H. Harris 2020-04-28 15:15:20 Re: Proposing WITH ITERATIVE
Previous Message Jonah H. Harris 2020-04-28 15:08:51 Re: Proposing WITH ITERATIVE