pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve <cheetah@tanabi.org>
To: Heikki Linnakangas <heikki@enterprisedb.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Question about PGSQL functions
Date: Thu, 8 Mar 2007 21:09:52 -0500 (EST)
Message-ID: <Pine.GSO.4.64.0703082105340.11576@kittyhawk.tanabi.org> (raw)
In-Reply-To: <45F099A0.5080401@enterprisedb.com>
References: <E1HOxqf-0005Mn-Uw@elasmtp-kukur.atl.sa.earthlink.net>
	<HCEPKPMCAJLDGJIBCLGHOEDCHEAA.james@mansionfamily.plus.com>
	<20070308084823.GA7216@svr2.hagander.net>
	<b42b73150703080611y64be6b11s2f580671d731cc09@mail.gmail.com>
	<E1HPNXd-0002mO-Rq@elasmtp-junco.atl.sa.earthlink.net>
	<b42b73150703081224j41bcc2barbc22495d833b8304@mail.gmail.com>
	<Pine.GSO.4.64.0703081715190.11576@kittyhawk.tanabi.org>
	<45F099A0.5080401@enterprisedb.com>

> Steve wrote:
>> IF  strlen(source.corrected_procedure_code)
>> THEN:
>>   summary.procedure_code=source.corrected_procedure_code
>>   summary.wrong_procedure_code=source.procedure_code
>> ELSE:
>>   summary.procedure_code=source.procedure_code
>>   summary.wrong_procedure_code=NULL
>
> Um, so you test if source.corrected_procedure_code is an empty string? And if 
> it is, summary.procedure_code is set to an empty string? But in 
> wrong_procedure_code, you use NULLs?

 	Yeah; we could use empty strings if that make it easier for 
whatever reason, but to our front end software NULL vs. empty string 
doesn't actually matter and we never query based on these columns, they're 
for display purposes only.

>> Simple, right?  Making a C function to handle this should be no sweat -- I 
>> would basically split this logic into two separate functions, one to 
>> populate summary.procedure_code and one to populate 
>> summary.wrong_procedure_code, and it removes the need of having any sort of 
>> back and forth between the program and DB... I can just do like:
>> 
>> update summary_table
>>  set procedure_code=pickCorrect(source.procedure_code,
>>                                  source.corrected_procedure_code),
>>      wrong_procedure_code=pickWrong(source.procedure_code,
>>                                  source.corrected_procedure_code),....
>>  from source where summary_table.source_id=source.source_id;
>
> ISTM you could write this easily with a little bit of SQL, with no need for 
> C-functions (I haven't run this, probably full of typos..) :
>
> update summary_table
>  set procedure_code = (CASE WHEN source.corrected_procedure_code = '' THEN 
> '' ELSE source.procedure_code END;),
>      wrong_procedure_code = (CASE WHEN source.corrected_procedure_code = '' 
> THEN source.procedure_code ELSE NULL END;)
>  from source where summary_table.source_id=source.source_id;

 	This looks interesting and I'm going to give this a shot tomorrow 
and see how it goes.  Speed is somewhat of an issue which is why I 
initially thought of the C function -- plus I wasn't aware you could do 
CASE statements like that :)  Thanks for the idea!


Steve



view thread (3+ messages)

Message-ID: <Pine.GSO.4.64.0703082105340.11576@kittyhawk.tanabi.org>
Permalink:  ../Pine.GSO.4.64.0703082105340.11576@kittyhawk.tanabi.org/
Also on:    postgresql.org/message-id/Pine.GSO.4.64.0703082105340.11576@kittyhawk.tanabi.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: cheetah@tanabi.org, heikki@enterprisedb.com
  Subject: Re: Question about PGSQL functions
  In-Reply-To: <Pine.GSO.4.64.0703082105340.11576@kittyhawk.tanabi.org>
  References: <E1HOxqf-0005Mn-Uw@elasmtp-kukur.atl.sa.earthlink.net> <HCEPKPMCAJLDGJIBCLGHOEDCHEAA.james@mansionfamily.plus.com> <20070308084823.GA7216@svr2.hagander.net> <b42b73150703080611y64be6b11s2f580671d731cc09@mail.gmail.com> <E1HPNXd-0002mO-Rq@elasmtp-junco.atl.sa.earthlink.net> <b42b73150703081224j41bcc2barbc22495d833b8304@mail.gmail.com> <Pine.GSO.4.64.0703081715190.11576@kittyhawk.tanabi.org> <45F099A0.5080401@enterprisedb.com> <Pine.GSO.4.64.0703082105340.11576@kittyhawk.tanabi.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox