Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTRsk-0000l6-7b for pgsql-admin@arkaria.postgresql.org; Tue, 28 Apr 2020 15:10:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jTRsj-0001Q1-5V for pgsql-admin@arkaria.postgresql.org; Tue, 28 Apr 2020 15:10:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTRsi-0001Pt-UU for pgsql-admin@lists.postgresql.org; Tue, 28 Apr 2020 15:10:44 +0000 Received: from jakobs.com ([85.214.83.89] helo=rs.plausibolo.de) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTRsc-0002TX-8x for pgsql-admin@lists.postgresql.org; Tue, 28 Apr 2020 15:10:43 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 8C886BE0C23 for ; Tue, 28 Apr 2020 17:10:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at rs.plausibolo.de Received: from rs.plausibolo.de ([127.0.0.1]) by localhost (h2367442.stratoserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UKC1CiORC1oI; Tue, 28 Apr 2020 17:10:32 +0200 (CEST) Received: from [192.168.178.86] (i5E86B0DD.versanet.de [94.134.176.221]) by rs.plausibolo.de (Postfix) with ESMTPSA id B9325BE007F; Tue, 28 Apr 2020 17:10:31 +0200 (CEST) Subject: Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length) To: pgsql-admin@lists.postgresql.org References: From: Holger Jakobs Message-ID: Date: Tue, 28 Apr 2020 17:10:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: de-DE List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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