pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Steve Baldwin <steve.baldwin@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: regr_slope returning NULL
Date: Sun, 24 Mar 2019 01:34:41 -0400
Message-ID: <32147.1553405681@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKE1AiYv2phXum3yN01Eorkj86JqarACyU_gtX1LSpT65EW9Uw@mail.gmail.com>
References: <CAKE1AiYv2phXum3yN01Eorkj86JqarACyU_gtX1LSpT65EW9Uw@mail.gmail.com>

Steve Baldwin <steve.baldwin@gmail.com> writes:
> Consider the following:
> ...
> log=# select id, regr_slope(elapsed, ts) as trend from sb1 group by id;
>   id  |        trend
> ------+----------------------
>  c742 |
>  317e |
>  5fe6 | 5.78750952760444e-06
>  3441 |
> (4 rows)

Hm, I get

regression=# select id, regr_slope(elapsed, ts) as trend from sb1 group by id;
  id  |         trend         
------+-----------------------
 c742 |    19.607858781290517
 317e |   -1.0838511987808963
 5fe6 | 5.787509483586743e-06
 3441 |    -3.828395463097356
(4 rows)

What platform are you doing this on, and what exactly is the PG version?

> If pg is correctly returning NULL, I'd be interested to understand the
> circumstances under which this can occur.

The source code shows two cases in which NULL would be returned:

	/* if N is 0 we should return NULL */
	if (N < 1.0)
		PG_RETURN_NULL();

	/* per spec, return NULL for a vertical line */
	if (Sxx == 0)
		PG_RETURN_NULL();

Maybe the cases you're looking at are sufficiently numerically
ill-conditioned that you could get Sxx == 0 depending on platform-
specific roundoff error, but it seems fishy.

			regards, tom lane




view thread (5+ messages)  latest in thread

Message-ID: <32147.1553405681@sss.pgh.pa.us>
Permalink:  ../32147.1553405681@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/32147.1553405681@sss.pgh.pa.us

 · 

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, steve.baldwin@gmail.com
  Subject: Re: regr_slope returning NULL
  In-Reply-To: <32147.1553405681@sss.pgh.pa.us>
  References: <CAKE1AiYv2phXum3yN01Eorkj86JqarACyU_gtX1LSpT65EW9Uw@mail.gmail.com> <32147.1553405681@sss.pgh.pa.us>

* 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