pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to compare dates from two tables with blanks values
3+ messages / 2 participants
[nested] [flat]

* How to compare dates from two tables with blanks values
@ 2018-12-19 10:41 Mike Martin <redtux1@gmail.com>
  2018-12-19 10:57 ` Re: How to compare dates from two tables with blanks values Arnaud L. <arnaud.listes@codata.eu>
  0 siblings, 1 reply; 3+ messages in thread

From: Mike Martin @ 2018-12-19 10:41 UTC (permalink / raw)
  To: pgsql-general

I have a situation where I need to update dates in a primary table from
regular imports of data, eg: this is the base select query

select d.row_id,
fname||lname,'joineddate',d.joineddate,'joineddate',s.joineddate,0 as bool1
from import s join  members d on d.contact_id=s.contact_id where

cast(nullif(d.joineddate,NULL) as timestamp) !=
cast(nullif(s.joineddate,'') as timestamp)

This gives zero records, however I cant seem to get a query that works.
For non-date fields I just use
Coalesce(fieldprime,'')!=coalesce(fieldiimport,'') which works fine but
chokes on dates where there is a blank value

thanks in advance

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to compare dates from two tables with blanks values
  2018-12-19 10:41 How to compare dates from two tables with blanks values Mike Martin <redtux1@gmail.com>
@ 2018-12-19 10:57 ` Arnaud L. <arnaud.listes@codata.eu>
  2018-12-21 13:48   ` Re: How to compare dates from two tables with blanks values Mike Martin <redtux1@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Arnaud L. @ 2018-12-19 10:57 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Le 19/12/2018 à 11:41, Mike Martin a écrit :
> cast(nullif(d.joineddate,NULL) as timestamp) != cast(nullif(s.joineddate,'') as timestamp) 
Try with
d.joineddate IS DISTINCT FROM s.joineddate

https://www.postgresql.org/docs/current/functions-comparison.html

Cheers
--
Arnaud




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to compare dates from two tables with blanks values
  2018-12-19 10:41 How to compare dates from two tables with blanks values Mike Martin <redtux1@gmail.com>
  2018-12-19 10:57 ` Re: How to compare dates from two tables with blanks values Arnaud L. <arnaud.listes@codata.eu>
@ 2018-12-21 13:48   ` Mike Martin <redtux1@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Mike Martin @ 2018-12-21 13:48 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

thanks for this. I did get it to work using coalesce and nullif on opposite
sides of the where condition, but the IS DISTINCT FROM certainly sounds a
better approach. Coming from SQLServer until last year , never came across
it before

Mike

On Wed, 19 Dec 2018 at 10:57, Arnaud L. <arnaud.listes@codata.eu> wrote:

> Le 19/12/2018 à 11:41, Mike Martin a écrit :
> > cast(nullif(d.joineddate,NULL) as timestamp) !=
> cast(nullif(s.joineddate,'') as timestamp)
> Try with
> d.joineddate IS DISTINCT FROM s.joineddate
>
> https://www.postgresql.org/docs/current/functions-comparison.html
>
> Cheers
> --
> Arnaud
>
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-12-21 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-12-19 10:41 How to compare dates from two tables with blanks values Mike Martin <redtux1@gmail.com>
2018-12-19 10:57 ` Arnaud L. <arnaud.listes@codata.eu>
2018-12-21 13:48   ` Mike Martin <redtux1@gmail.com>

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