dbTalk Databases Forums  

[ADMIN] case statement to cath nulls on joined tables

mailing.database.pgsql-admin mailing.database.pgsql-admin


Discuss [ADMIN] case statement to cath nulls on joined tables in the mailing.database.pgsql-admin forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John Morgan
 
Posts: n/a

Default [ADMIN] case statement to cath nulls on joined tables - 02-03-2012 , 06:45 AM






Hello,

I am doing a left outer join between a polygon table and a data table.
Everything
returns fine from this join as expected. However, there are cases where
there isn?t data for a given polygon and this return as the expected null
in the result set. I would like to utilize something like a case statement
to catch the nulls and return a ?more friendly? message. I have tried
unsuccessfully to use the following logic:

*Select case value_of_interest null then ?more friendly message? else
value_of_interest end*

*From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id*

If someone could let me know where I am going wrong it would be greatly
appreciated.

Cheers,

Derek

Reply With Quote
  #2  
Old   
Matheus de Oliveira
 
Posts: n/a

Default Re: [ADMIN] case statement to cath nulls on joined tables - 02-03-2012 , 09:05 AM






Try that:

SELECT address, CASE WHEN value_of_interest IS NULL THEN 'more friendly
message' ELSE value_of_interest END value_of_interest
From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id


--
Matheus de Oliveira




On Fri, Feb 3, 2012 at 10:45 AM, John Morgan <jdmorgan (AT) unca (DOT) edu> wrote:

Quote:
Hello,

I am doing a left outer join between a polygon table and a data table.
Everything
returns fine from this join as expected. However, there are cases where
there isn?t data for a given polygon and this return as the expected null
in the result set. I would like to utilize something like a case statement
to catch the nulls and return a ?more friendly? message. I have tried
unsuccessfully to use the following logic:

*Select case value_of_interest null then ?more friendly message? else
value_of_interest end*

*From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id*

If someone could let me know where I am going wrong it would be greatly
appreciated.

Cheers,

Derek

Reply With Quote
  #3  
Old   
Matheus de Oliveira
 
Posts: n/a

Default Re: [ADMIN] case statement to cath nulls on joined tables - 02-03-2012 , 09:09 AM



Even better:

SELECT COALESCE(value_of_interest, 'more friendly message')
value_of_interest
From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id

--
Matheus de Oliveira




On Fri, Feb 3, 2012 at 1:05 PM, Matheus de Oliveira <
matioli.matheus (AT) gmail (DOT) com> wrote:

Quote:
Try that:

SELECT address, CASE WHEN value_of_interest IS NULL THEN 'more friendly
message' ELSE value_of_interest END value_of_interest

From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id


--
Matheus de Oliveira





On Fri, Feb 3, 2012 at 10:45 AM, John Morgan <jdmorgan (AT) unca (DOT) edu> wrote:

Hello,

I am doing a left outer join between a polygon table and a data table.
Everything
returns fine from this join as expected. However, there are cases where
there isn?t data for a given polygon and this return as the expected null
in the result set. I would like to utilize something like a case
statement
to catch the nulls and return a ?more friendly? message. I have tried
unsuccessfully to use the following logic:

*Select case value_of_interest null then ?more friendly message? else
value_of_interest end*

*From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id*

If someone could let me know where I am going wrong it would be greatly
appreciated.

Cheers,

Derek



Reply With Quote
  #4  
Old   
jdmorgan
 
Posts: n/a

Default Re: [ADMIN] case statement to cath nulls on joined tables - 02-03-2012 , 12:34 PM



Thanks Matheus. The coalesce method worked like a champ.

Cheers,
Derek

On 2/3/2012 10:09 AM, Matheus de Oliveira wrote:
Quote:
Even better:

SELECT COALESCE(value_of_interest, 'more friendly message')
value_of_interest
From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id

--
Matheus de Oliveira




On Fri, Feb 3, 2012 at 1:05 PM, Matheus de Oliveira
matioli.matheus (AT) gmail (DOT) com <mailto:matioli.matheus (AT) gmail (DOT) com>> wrote:

Try that:

SELECT address, CASE WHEN value_of_interest IS NULL THEN 'more
friendly message' ELSE value_of_interest END value_of_interest

From poly_table left outer join data_table one
poly_table.common_id = data_table.common_id


--
Matheus de Oliveira





On Fri, Feb 3, 2012 at 10:45 AM, John Morgan <jdmorgan (AT) unca (DOT) edu
mailto:jdmorgan (AT) unca (DOT) edu>> wrote:

Hello,

I am doing a left outer join between a polygon table and a
data table.
Everything
returns fine from this join as expected. However, there are
cases where
there isn?t data for a given polygon and this return as the
expected null
in the result set. I would like to utilize something like a
case statement
to catch the nulls and return a ?more friendly? message. I
have tried
unsuccessfully to use the following logic:

*Select case value_of_interest null then ?more friendly
message? else
value_of_interest end*

*From poly_table left outer join data_table one
poly_table.common_id =
data_table.common_id*

If someone could let me know where I am going wrong it would
be greatly
appreciated.

Cheers,

Derek




--
Derek @ NEMAC

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.