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 1lu8JR-0003Ww-MG for pgsql-general@arkaria.postgresql.org; Fri, 18 Jun 2021 06:49:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lu8JQ-0005p1-Bz for pgsql-general@arkaria.postgresql.org; Fri, 18 Jun 2021 06:49:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lu8JP-0005ot-VA for pgsql-general@lists.postgresql.org; Fri, 18 Jun 2021 06:49:08 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lu8JM-0003np-LR for pgsql-general@lists.postgresql.org; Fri, 18 Jun 2021 06:49:07 +0000 Received: by mail-ej1-x629.google.com with SMTP id dm5so1743682ejc.9 for ; Thu, 17 Jun 2021 23:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=mxtKcxXGJOSqyF0bAufpqE7byfEqnIuDdKYEGKehUBk=; b=TIIlc2ZuCjRvMviAyypf/Mo/PjL8iXeQNJp+e9JU4NghpttNM0SvUdYzryGBDaMO3a VlsucR0ErwJSL5tDDsSIH/m1oDGdNPQ3tVcrgUPZRXGPzHWoeJYi+KLCvnYsJcbtlMKi reLdncQk8LxPDnpNjf+a/YWRrIWkvUifwZktqgHH3s/qmJdSUx3YeVfpbpjEc2zhN4Ir cNW8pXZwpxFuNpjUYVzqI8sk7y93ARMnZl3P0DfVD1fmGuCdtD3vUW5wEYn9pPCKcODY K1n2bn9Ekg8sOgof6zwnpLaBQdqqa1gsXMF4atvsz/w0RsSmqPabzwxFPpB+64N1jWAR bUBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=mxtKcxXGJOSqyF0bAufpqE7byfEqnIuDdKYEGKehUBk=; b=o4IAfqpiUJU+2m3uF3qAaYIGitLweDz56qC8C+uWjwgm3VJHNsXPOL/FRVdxWvhksY 4ZDvZtUBwpnwKBH1GWodd/kOuLv+nLHU0187iZ8MI5jpGtVZg9XN4/4DZ9/9VNn2YTd1 flcarRiaJIjho05ADvIZIVxaWfvy4o5CJQleYBX45b7GGNPNbiPvkO7mmcCxkzbFjFU7 zzegXPUt3PRSoKsW2bC6rz3/TjTLFWyBgofcpYld2Y55GFx9PHHBtm7BYu3Gho6IU+Ti +lps8jHFN5fM0szWgDwAWfft5HmM3a2mPTPi7rSznwOdrf927bGmujW0rq/1uUGspnMb Z0gw== X-Gm-Message-State: AOAM531tIhs/yFr4bPzae3pyXECCg9c3BUOZ8g57JyN4++jC0FmuWfUr lt5hkeThf3hYdEwwKzaO6rnGm18LibXsaQ== X-Google-Smtp-Source: ABdhPJyf0hVFDHmHCa5kNXrl4JkWGZ5xrbcK3o6lxp0JfBMdLlh1Rg2jIU7BGgTo6hmv2jaRgoZG9A== X-Received: by 2002:a17:907:3f08:: with SMTP id hq8mr9422091ejc.150.1623998942732; Thu, 17 Jun 2021 23:49:02 -0700 (PDT) Received: from localhost.localdomain (217-149-169-135.nat.highway.telekom.at. [217.149.169.135]) by smtp.gmail.com with ESMTPSA id j24sm5759049edv.48.2021.06.17.23.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 23:49:02 -0700 (PDT) Message-ID: <2a26524e395daee321efe6ffc391fd2debec55dc.camel@cybertec.at> Subject: Re: A simple question about text fields From: Laurenz Albe To: Gavan Schneider , "David G. Johnston" Cc: Tom Lane , Martin Mueller , pgsql-general@lists.postgresql.org Date: Fri, 18 Jun 2021 08:49:01 +0200 In-Reply-To: <2DE3A34D-EEC7-4167-B8FA-3BB168410B7B@pendari.org> References: <677775.1623856129@sss.pgh.pa.us> <2DE3A34D-EEC7-4167-B8FA-3BB168410B7B@pendari.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2021-06-18 at 10:28 +1000, Gavan Schneider wrote: > On 18 Jun 2021, at 9:34, David G. Johnston wrote: > > On Thursday, June 17, 2021, Gavan Schneider wrote: > > > > > My approach is to define such fields as ‘text’ and set a constraint using > > > char_length(). This allows PG to do the business with the text in native > > > form, and only imposes the cost of any length check when the field is > > > updated… best of both worlds. > > > > > > > Those are basically the same world…your alternative probably is strictly > > worse than varchar(n) because of its novel way of implementing the same > > functionality. > > Not sure if this is strictly true. Novelty per se is not always worse. :) True in general, but not in this case. There is no advantage in a "text" with a check constraint on the length, that is, no added functionality. And it is worse for these reasons: - the performance will be worse (big reason) - the length limit is less obvious if you look at the table definition (small reason) Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com