X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D5BBE3A4ACF for ; Fri, 19 Nov 2004 22:28:10 +0000 (GMT) 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 26906-10 for ; Fri, 19 Nov 2004 22:28:07 +0000 (GMT) Received: from svr4.postgresql.org (unknown [66.98.251.159]) by svr1.postgresql.org (Postfix) with ESMTP id 43D5C3A4B13 for ; Fri, 19 Nov 2004 20:47:14 +0000 (GMT) Received: from skycasters.net (ns2.skycasters.com [204.232.30.3]) by svr4.postgresql.org (Postfix) with ESMTP id F1F745AF94B for ; Fri, 19 Nov 2004 20:19:39 +0000 (GMT) Received: from rhino.esc1.com [206.71.98.3] by skycasters.net with ESMTP (SMTPD32-8.12) id A51A846F00E2; Fri, 19 Nov 2004 15:18:34 -0500 Received: from rhino.esc1.com (localhost.localdomain [127.0.0.1]) by rhino.esc1.com (8.12.11/8.12.10) with ESMTP id iAJKEXJj028960 for ; Fri, 19 Nov 2004 15:14:33 -0500 Received: from localhost (localhost [[UNIX: localhost]]) by rhino.esc1.com (8.12.11/8.12.11/Submit) id iAJKEWqh028958 for pgsql-sql@postgresql.org; Fri, 19 Nov 2004 15:14:32 -0500 From: Terry Lee Tucker Organization: Enhanced Solutions Computing To: Subject: Re: NULLS and string concatenation Date: Fri, 19 Nov 2004 15:14:32 -0500 User-Agent: KMail/1.5.3 References: <71E37EF6B7DCC1499CEA0316A256832801D4BB44@loki.wc.globexplorer.net> In-Reply-To: <71E37EF6B7DCC1499CEA0316A256832801D4BB44@loki.wc.globexplorer.net> MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200411191514.32896.terry@esc1.com> X-Declude-Sender: terry@esc1.com [127.0.0.1] X-Declude-Spoolname: D5517846f00e22d3f.SMD X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/208 X-Sequence-Number: 19527 Slick ;o) This goes in my tool kit... On Friday 19 November 2004 03:03 pm, Gregory S. Williamson saith: > Someone on this list provided me with a rather elegant solution to this a > few weeks ago: > > CREATE OR REPLACE FUNCTION text_concat_nulls_with_an_embedded_space(text, > text) RETURNS text AS 'SELECT CASE WHEN $1 IS NULL THEN $2 WHEN $2 IS NULL > THEN $1 ELSE $1 || '' '' || $2 END' LANGUAGE sql; > > CREATE OPERATOR ||~ (PROCEDURE = text_concat_nulls_with_an_embedded_space, > LEFTARG = text, RIGHTARG = text); > > And I call it as: > SELECT (trim(s_directio) ||~ trim(s_house) ||~ trim(s_post_dir) ||~ > trim(s_street) ||~ trim(s_suffix)) as street ... (yadda yadda) > > Deals quite neatly with the NULLs in some of the columns. > > HTH, > > Greg Williamson > DBA > GlobeXplorer LLC > > -----Original Message----- > From: Michael Fuhr [mailto:mike@fuhr.org] > Sent: Fri 11/19/2004 9:53 AM > To: Don Drake; pgsql-sql@postgresql.org > Cc: > Subject: Re: [SQL] NULLS and string concatenation > > On Fri, Nov 19, 2004 at 11:45:43AM -0600, Bruno Wolff III wrote: > > On Fri, Nov 19, 2004 at 11:12:38 -0600, Don Drake wrote: > > > I was able to work around the problem by using COALESCE (and casting > > > variables since it wants the same data types passed to it). > > > > This is what you should do. > > If you don't mind using a non-standard feature, another possibility > would be to create an operator similar to || that COALESCEs NULLs > into empty strings. > > -- > Michael Fuhr > http://www.fuhr.org/~mfuhr/ > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org -- Quote: 87 "The federal government has taken too much tax money from the people, too much authority from the states, and too much liberty with the Constitution." --Ronald Reagan Work: 1-336-372-6812 Cell: 1-336-363-4719 email: terry@esc1.com