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 E264ED1B901 for ; Mon, 23 Feb 2004 05:18:48 +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 66811-04 for ; Mon, 23 Feb 2004 01:18:47 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 6777FD1B8F2 for ; Mon, 23 Feb 2004 01:18:46 -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 i1N5Ij1Y040987 for ; Mon, 23 Feb 2004 05:18:45 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i1N4oUpv037538 for pgsql-sql@postgresql.org; Mon, 23 Feb 2004 04:50:30 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.sql Subject: Re: User defined types -- Social Security number... Date: Sun, 22 Feb 2004 23:07:13 -0500 Organization: cbbrowne Computing Inc Lines: 41 Message-ID: References: <200402221132.50311.josh@agliodbs.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:4OYtmFaSwg+8wf9LUfrJuIMFKtI= To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/336 X-Sequence-Number: 17026 In the last exciting episode, "Greg Patnude" wrote: > Thanks Josh -- I understand that there are valid and invalid SSN's -- > similar rules apply to zip codes and area codes... > > I tried this: > > SELECT to_char(123456789, '000-00-0000'); > which yields 123-45-6789 -- nicely, I might add... > > the trick is getting postgreSQL to do this without having to create an ON > SELECT and ON UPDATE TRIGGER... > > an ON UPDATE, SELECT, and INSERT re-write RULE might do the trick... > > SSN's CAN in fact start with a leading 0 -- mine does -- "041-xx-xxxx" -- > > I do agree that there are valid ranges -- my main concern is being able to > store any leading zeros - I just need to make sure that something "looks" > like a valid SSN in the formattig > (nnn-nn-nnnn) and that I can store / retrieve it with the approoriate > format -- what I am really trying to accomplish is an "input mask"... > > I hadn't considered using a Domain.... have to look at that.... Strongly recommended; that allows applying the validation in many places without having to repeat validation "code." If you will be using really a lot of these values, and indexing on them, it even may be worth looking at a custom type. A performance "win" would come in using a compact data type. For instance, for 9 digit national ID numbers, you can do a LOT better than an 11 byte string. (Aside: Anything bigger than 34 bits would do, demonstrating that it is a regrettable loss that 36 bit computer systems went the way of the dodo...) -- output = reverse("gro.gultn" "@" "enworbbc") http://www.ntlug.org/~cbbrowne/internet.html I found out why cats drink out of the toilet. My mother told me it's because it's cold in there. And I'm like: How did my mother know THAT? --Wendy Liebman