X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 73EE3476416 for ; Wed, 14 May 2003 14:02:00 -0400 (EDT) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with ESMTP id 15525-04 for ; Wed, 14 May 2003 14:01:57 -0400 (EDT) Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net [194.217.242.90]) by postgresql.org (Postfix) with ESMTP id 0488F4763EE for ; Wed, 14 May 2003 14:01:57 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 3.35 #1) id 19G0Zg-000Ae5-0W; Wed, 14 May 2003 19:01:56 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id A6D3916F38; Wed, 14 May 2003 19:01:54 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 2673016A50; Wed, 14 May 2003 19:01:54 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: Randall Lucas Subject: Re: Type coercion on column in a query Date: Wed, 14 May 2003 19:01:51 +0100 User-Agent: KMail/1.4.3 Cc: "Kenny Mok" , References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200305141901.51714.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/295 X-Sequence-Number: 13460 On Wednesday 14 May 2003 5:46 pm, Randall Lucas wrote: > Thanks Richard, > > Do you know if there's a way to access the same method that Postgres > uses for determining cast-ability? I don't *think* so (bear in mind I'm not a developer, just a user). My=20 understanding is that PG does the following: 1. Identify types involved 2. Look up the function required to convert 3. Execute the function It's the function itself that raises an error in the case of say=20 text=3D>timestamp where the text contains garbage. I don't think there's mu= ch=20 the developers can do about this - if you want to be able to add new types= =20 simply, they need to be fairly self contained.=20 Now it shouldn't be beyond the wit of man to be able to produce an=20 is_castable(value, destination_type) function that calls these conversion= =20 functions and traps the error. In this particular case there shouldn't* be= =20 any side effects to worry about. However, that's probably more work than=20 you're interested in. > I don't mind writing a new function in plperl. I am concerned not so > much about the difficulty of the numeric type, but as I move into other > types, such as timestamp, I don't want to re-implement half-assedly the > heuristics for date determination when those are already pretty > bulletproof in Postgres. I think you're out of luck here. The "proper" way to do this is: 1. try to insert values into columns of correct type=20 2. when it fails, handle error in application * - that's shouldn't as in I can't think of a good reason why right now --=20 Richard Huxton