X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 32F96D1E132 for ; Mon, 1 Mar 2004 05:20:28 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 82968-10 for ; Mon, 1 Mar 2004 01:20:17 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id EE318D1DAB9 for ; Mon, 1 Mar 2004 01:20:16 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i215KG1Y054460 for ; Mon, 1 Mar 2004 05:20:16 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i214oW5u050640 for pgsql-sql@postgresql.org; Mon, 1 Mar 2004 04:50:32 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.sql Subject: Re: User defined types -- Social Security number... Date: Sun, 29 Feb 2004 23:11:31 -0500 Organization: cbbrowne Computing Inc Lines: 47 Message-ID: References: <200402221132.50311.josh@agliodbs.com> <20040301031716.GB4046@michaelchaney.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through Obscurity, linux) Cancel-Lock: sha1:GTblkscCnK7GnJnqYD5x/ECSmLc= To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/1 X-Sequence-Number: 17100 The world rejoiced as mdchaney@michaelchaney.com (Michael Chaney) wrote: > Look, you're thinking way too hard on this. An SSN is a 9-digit number, > nothing more. There are some 9-digit numbers which aren't valid SSN's, > and you might want to get fancy and create a constraint for that. > > Regardless, you are making a *major* mistake of confusing data > storage with rendering. It is common to *render* an SSN as > xxx-xx-xxxx and its cousin the FETID (Federal Employers Tax ID) as > xx-xxxxxxx. To store the dashes makes no sense. They're in the > same place each time, it's wasted data. > > Store the SSN as an "integer". When you begin to think about this > correctly, the "leading zeros" problem disappears since that is also a > *rendering* issue. Well put. The one thing that is a bit unfortunate is that 32 bit ints aren't quite big enough for this. You need 1 extra digit :-(. > When you pull the data out, either fix it up in your programming > language to the format that you wish, or use the to_char function as > shown above in your select statements. Using a view to hide the "physical" representation is also an idea. A full scale type definition could make for an even more efficient approach that makes the implementation appear invisible. > To help you think about this whole issue, consider the timestamp > datatype. Timestamps are stored as a Julian date internally. I > suspect that they use a double-floating point as the actual format, > but regardless the point is that it's a number. Rather than storing Actually, it's an "int64"; a 64 bit integer, on platforms that support that type. It's a "double" only on platforms that do not support that type. > It's easier to use that as a basic format from which we can render > it in any way we wish. Indeed. -- If this was helpful, rate me http://cbbrowne.com/info/spiritual.html "I owe the government $3400 in taxes. So I sent them two hammers and a toilet seat." -- Michael McShane