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 1jTfIV-0003Is-RK for pgsql-admin@arkaria.postgresql.org; Wed, 29 Apr 2020 05:30:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jTfIT-00014m-0C for pgsql-admin@arkaria.postgresql.org; Wed, 29 Apr 2020 05:30:13 +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 1jTfIS-00014d-K3 for pgsql-admin@lists.postgresql.org; Wed, 29 Apr 2020 05:30:12 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jTfIQ-0001UJ-DH for pgsql-admin@lists.postgresql.org; Wed, 29 Apr 2020 05:30:11 +0000 Received: by mail-pl1-x62a.google.com with SMTP id z6so423123plk.10 for ; Tue, 28 Apr 2020 22:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:subject:in-reply-to:message-id:date :mime-version:content-transfer-encoding; bh=TG8tI4BqUsezvKe9qAbMcYrq3qexqdtDAk8/91x+D9g=; b=m+TLUJ4CfJ0HtJQQeKy/5xtqzZsfl7RMf/f7om8F1r5bgrPrRw3MExs+BhWZx/dL7X mdhbFO4A1sefhHpIJiCeBprGJZsxCFLratGXKnR83SmHi81WwZPDEskF2XQ7Z1wu0LtJ u3B8WYfsj3cJ9Rk51WNkjUO2VP1BBVRpL5D2pzakow56akRErLkPBckHCwdGmIE7JF1+ qUsbhh6zLk5asObD7MZPITTUlyP93ZIgC/Ga0vYhnLc+pbzKSVEaS4j9hF4G9UwUQ4CW bzqBV94EJZyqCuNQ3LYgMIXNV4YlVV2FnYmPIUnrhg33CHHiS5xx3H/9/tC2ehXtGoeM 5wHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:subject :in-reply-to:message-id:date:mime-version:content-transfer-encoding; bh=TG8tI4BqUsezvKe9qAbMcYrq3qexqdtDAk8/91x+D9g=; b=ubO02DAUmIcuNYWZS4yU38dRXAEQEyqyWNf6SjsPypqPzOW4ik28nSQOaJyymmUuuR wuYz57Nx4qqZ50IKenmn4s7VwOr1ZpqBt7ygDDG1NZPWou0nfE3aL/ZcKIXFgMaNzqD0 owM2UU+0YbWIPfGKHz+z84BBcL+aeN3EtqB8wLFlxbi5TdvVCcM3ZVMmf/OE0AfGY9Sl nPEliS1yYVg8j50NFbzEzhHs9PpCqgwBkV9ywC3SKvwUnCWGHQP0naBTgtU6eioq9Lbh Qp+qIRNXl27Nbgo9IauckQ7EBeSyb2cNFOl6IS4d8OOtT6cmVFPtLY02iNVy0NL1r2H4 ueag== X-Gm-Message-State: AGi0Pub94paS7oxEDIfPDci1ePQqSdFMk8Mx5Y+0LUc0gxZX4+y94Der cjIjZ54LAwfGbhbN7qMGJciyCRCX X-Google-Smtp-Source: APiQypKodpleUfPLZpYCHWrBj6/J3ylijQuTi2eykiK0T8SRQI7RYO/5eBIHfJVY9UtoXLdEkMFzkQ== X-Received: by 2002:a17:90a:f995:: with SMTP id cq21mr1163805pjb.56.1588138208965; Tue, 28 Apr 2020 22:30:08 -0700 (PDT) Received: from tim-desktop (203-173-20-216.dyn.iinet.net.au. [203.173.20.216]) by smtp.gmail.com with ESMTPSA id gn20sm3596808pjb.24.2020.04.28.22.30.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 22:30:08 -0700 (PDT) References: <20200428234332.7nkyomr2unlez6p5@raf.org> <8EC9D082-B541-435F-9EE3-3ED14AA3C2D1@crazybean.net> <20200429022928.fywdmiuc6oqpmgtc@raf.org> User-agent: mu4e 1.4.1; emacs 27.0.91 From: Tim Cross To: pgsql-admin@lists.postgresql.org Subject: Re: PostgreSQL CHARACTER VARYING vs CHARACTER VARYING (Length) In-reply-to: Message-ID: <87pnbqsvtw.fsf@gmail.com> Date: Wed, 29 Apr 2020 15:30:03 +1000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rui DeSousa writes: >> On Apr 28, 2020, at 10:29 PM, raf wrote: >>=20 >> Rui DeSousa wrote: >>=20 >>>> On Apr 28, 2020, at 7:43 PM, raf wrote: >>>>=20 >>>> I just use "text" for everything. It's less typing. :-) >>>=20 >>> Ugh, I see it as sign that the designers of the schema didn=E2=80=99t f= ully >>> think about the actual requirements or care about them and it usually >>> shows. >>=20 >> You are mistaken. I care a lot. That's why I >> future-proof designs whenever possible by >> not imposing arbitrarily chosen limits that >> appear to suit current requirements. >>=20 >> In other words, I know I'm not smart enough >> to predict the future so I don't let that >> fact ruin my software. :-) >>=20 >> cheers, >> raf >>=20 > > Arbitrarily? What=E2=80=99s a cusip, vin, ssn? Why would you put a btree= index on a text field? Because it=E2=80=99s not. > > What you=E2=80=99re advocating is a NoSQL design =E2=80=94 defer your sch= ema design. Letting the application code littered in multiple places elsew= here define what a cusip, etc. is.=20 I think the key term in this thread is 'arbitrary'. When implementing a schema design, it should reflect the known constraints inherent in the model, but it should avoid imposing arbitrary constraints if none exist or cannot be determined. So, if you know that a customer ID field has a current limitation of 50 characters, then use a definition which reflects that. It may be that at some point in the future, this will be increased, but then again, it may not and that bit of information provides useful information for application developers and helps with consistency across APIs. Without some guideline, different developers will impose different values, leading to maintenance issues and bugs down the track. On the other hand, imposing an arbitrary limitation, based on little more than a guess by the designer, can cause enormous problems. As an example, I was working on an identity management system where there was a constraint of 8 characters on the username and password. This was an arbitrary limit based on what was common practice, but was not a limitation imposed by any of the systems the IAM system interacted with. It was recognised that both fields were too small and needed to be increased. The easy solution would have been to make these fields text. However, that would cause a problem with some of the systems we needed to integrate with because either they had a limit on username size or they had a limit on password size. There were also multiple different APIs which needed to work with this system and when we performed analysis, they had varying limits on both fields. What we did was look at all the systems we had to integrate with and found the maximum supported username and password lengths for each system and set the fields to have the maximum length supported by the systems with the shortest lengths. Having that information in the database schema also informed those developing other interfaces what the maximums were. It is quite likely these limits would be increased in the future and the database definition would need to be increased - in fact, some years after going into production, exactly this occurred with the password field when a different encryption algorithm was adopted which did not have the previous character limitation and the client wanted to encourage users to use pass phrases rather than a word.=20 The point is, just using text for all character fields loses information and results in your model and schema being less expressive. Providing this information is sometimes critical in ensuring limits are maintained and provides useful documentation about the model that developers can use. However, imposing limits based on little more than a guess is usually a bad idea and if you cannot find any reason to impose a limit, then don't. I disagree with approaches which claim using text everywhere is easier and future proofing. In reality, it is just pushing the problem out for someone else to deal with. The best way to future proof your application is to have a clear well defined data model that fits the domain and is well documented and reflected in your database schema.=20 --=20 Tim Cross