X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 34342D705A for ; Fri, 26 Aug 2005 03:51:01 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77572-04 for ; Fri, 26 Aug 2005 06:50:55 +0000 (GMT) Received: from svana.org (svana.org [203.20.62.76]) by svr1.postgresql.org (Postfix) with ESMTP id 4FD80D78CD for ; Fri, 26 Aug 2005 03:50:54 -0300 (ADT) Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian)) id 1E8Y39-0001VW-00; Fri, 26 Aug 2005 16:50:51 +1000 Date: Fri, 26 Aug 2005 08:50:50 +0200 From: Martijn van Oosterhout To: "Matt A." Cc: pgsql-general@postgresql.org Subject: Re: help Message-ID: <20050826065045.GA4848@svana.org> Reply-To: Martijn van Oosterhout Mail-Followup-To: "Matt A." , pgsql-general@postgresql.org References: <20050825220609.GF17679@svana.org> <20050825231027.46422.qmail@web35201.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="envbJBWh7q8WU6mo" Content-Disposition: inline In-Reply-To: <20050825231027.46422.qmail@web35201.mail.mud.yahoo.com> User-Agent: Mutt/1.3.28i X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003] X-Spam-Level: X-Archive-Number: 200508/1318 X-Sequence-Number: 82726 --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 25, 2005 at 04:10:27PM -0700, Matt A. wrote: > Anyway, I am new to postgres and looking to casts. I > have wrote this question several times before and on > this version I forgot to add the exact rules of why > it's breaking and what i need it to do. I will try to > be more clear...=20 >=20 > I use the rules to insert 0/1/null inserts into > booleans, integers, text, etc. fields. >=20 > Example: insert into table (bool_column) values > nullif('','')); > ERROR: column "bool_column" is of type boolean but=20 > expression is of type text. First rule, the type of a functions is determined by its arguments. Neither of the arguments in your example are boolean so it doesn't know you want a boolean. nullif itself works on any type. kleptog=3D# create temp table x (t text, b bool, i integer); CREATE TABLE kleptog=3D# insert into x values (nullif('1','1'), nullif(true,true), nullif(4,4) ); INSERT 114774 1 kleptog=3D# select * from x; t | b | i=20 ---+---+--- | | =20 (1 row) All nulls... Your choice are to indicate in the arguments what type you want. In this case the arguments arn't booleans so that won't work. Your other option is to cast the result, which you can't because text -> bool is not a valid typecast. >=20 > Where '' =3D=3D '' should evaluate to NULL as OPAQUE > (depreciated) or similiar return instead of TEXT cast. >=20 > So if I could alter the cast from text to return > either INTEGER or TEXT, that would super! I'm not sure > if it's possible but if so I'm willing to do what it > takes to accomplish it.=20 Functions don't return OPAQUE, they can't because a function knows exactly what it's returning. In your case it's returning TEXT because that's what the arguments default to if it doesn't know any better. Technically, nullif takes arguments (anyelement,anyelement) which means it can take any type, as long as they're the same. Hope this clarifies it for you. --=20 Martijn van Oosterhout http://svana.org/kleptog/ > Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a > tool for doing 5% of the work and then sitting around waiting for someone > else to do the other 95% so you can sue them. --envbJBWh7q8WU6mo Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQFDDrvEIB7bNG8LQkwRAm5pAJ0VNMhX1CpAqs9BYRrecKS/3TlmBQCeIuK5 pQGw/Bq+LXRzKI09DG8HfUs= =5nSo -----END PGP SIGNATURE----- --envbJBWh7q8WU6mo--