if statement - Mailing list pgsql-novice

From Devinder K Rajput
Subject if statement
Date
Msg-id OF39804F6D.3E809375-ON86256C59.005A3C80@ipaper.com
Whole thread Raw
Responses Re: if statement  (Ludwig Lim <lud_nowhere_man@yahoo.com>)
List pgsql-novice
Hi,

I am trying to find out how to do an if statement/case statement inside a
select.  I am comparing item records to find out what is different.  Rather
than writing a query for comparing each field separately, I just want to
tell which field is different by printing the name of that field.  Thank
you.

select
  a.number,
  a.description_1,
  a.description_2,
  b.description_1,
  b.description_2,
  a.hub_id,
  b.hub_id,
  a.category,
  b.category,
  a.sub_category,
  b.sub_category,
--what I would like to say--
  if a.description_1 <> b.description_1 "description_1"
  else if a.description_2 <> b.description_2 "description_2"
  else if ...
---back to rest of query---
from items as a, items as b
where  a.number = b.number
     and a.hub_id <> b.hub_id
     and (a.category <> b.category OR a.sub_category <> b.sub_category OR
             a.prime_vendor <> b.prime_vendor OR a.description_1 <>
b.description_1 OR
             a.description_2 <> b.description_2 OR a.prc_unit <> b.prc_unit
OR
             a.alt_unit_1 <> b.alt_unit_1 OR a.alt_unit_2 <> b.alt_unit_2
OR
             a.alt_unit_3 <> b.alt_unit_3 OR a.prime_vendor_cost <>
b.prime_vendor_cost )
     and a.hub_id < b.hub_id




Devinder Rajput
Stores Division Corporate Offices
Chicago, IL
(773) 442-6474



pgsql-novice by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: how to create secondary key!!
Next
From: Andrew McMillan
Date:
Subject: Re: db design question