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 1jTTH9-0003Ud-2v for pgsql-admin@arkaria.postgresql.org; Tue, 28 Apr 2020 16:40:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jTTH7-0003su-CF for pgsql-admin@arkaria.postgresql.org; Tue, 28 Apr 2020 16:40:01 +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 1jTTH7-0003sm-2Y for pgsql-admin@lists.postgresql.org; Tue, 28 Apr 2020 16:40:01 +0000 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jTTH0-0003Ks-Of for pgsql-admin@lists.postgresql.org; Tue, 28 Apr 2020 16:40:00 +0000 Received: by mail-ot1-x344.google.com with SMTP id c3so33707499otp.8 for ; Tue, 28 Apr 2020 09:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=eF8YOK2Ox1HK2PRq4aij9hTh3zdu6DVfBhtsk4JMWcs=; b=UTsBreYs8+uKW+mqYp4MsnEwfS2Wo8jshiCFu8OxbTqcsqNBp45f4qGtm/2HyV1p5p Pz0NFY6BU1b4o0N1zQO9IcrcmIyVWfg9MH0ggwJPRzpTQaHSpABZF/lT5W4APuPD0tWt pTopLawhqMBQQjUi3VqOfPSJyQBlqEwcK+2PRECFzDnawSdd98iSEknhznUMGawfNFY4 pWyHYEaA5o5DJbaSq/zCaoZ3kbf4ZMoEDpJmEM+Dko46jmqQ4b9jYhaBubkwc/UTuaxs qI/87tujsw/xji4U45zjoIsVS+eOKjuMMIf/91/PrgmD66XmI1kp+mZYclTnx1ivgQZ+ xqHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=eF8YOK2Ox1HK2PRq4aij9hTh3zdu6DVfBhtsk4JMWcs=; b=t2v/BqZvu8Ew0c/PdABLusBVkgsQnnO+soMJjnuQvVXzC98Ams01oGPN0qwdEgF0FN 56hmQNBTIirMBnrRf19E8YfkThMre1tQTmzCZq2HcczQ0c3C1OSOHA2itCNtNogJ7WVO xKjRkwUpesfkg2LH1r9b4rQYT5tb0Evk9ZNj9CRxc+lIV03tyGTNPFpjdR+ceVprMkwE /Sap0AnLMbTsf00cibSR0W1GE58x5Q703VOen0SyR4vmhK31L4jatR1Gop9n1AorGiKM 6x13QloEvmgYjWs9SdzGMSO4Iak18/opOCRc9QBm6BRAJ+F22FKXFmlwUif2++A5/ILy KCcw== X-Gm-Message-State: AGi0PuYX4swaudf5rSDxV7NBk5g7uErlnXCcW4scjFdg/JcsmNqXcwZ/ 2qgnMb5H+ESDKFNuc4Vq3J6rYhPUAOk= X-Google-Smtp-Source: APiQypIN56OWrMORkh4JAJ7602AZxSwYUALBGYAKwtmZtsSlQ3iT7KZGg7p1t9b9QOU8RwiCXxUgMA== X-Received: by 2002:a9d:191:: with SMTP id e17mr1512808ote.21.1588091993666; Tue, 28 Apr 2020 09:39:53 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id a132sm666735oib.16.2020.04.28.09.39.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Apr 2020 09:39:53 -0700 (PDT) Subject: Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length) To: pgsql-admin@lists.postgresql.org References: From: Ron Message-ID: <8d6eface-4bde-b165-34f1-eeaefe88a6aa@gmail.com> Date: Tue, 28 Apr 2020 11:39:52 -0500 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: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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.