pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Sebastian P. Luque <spluque@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: custom average window function failure
Date: Sun, 9 Oct 2016 08:37:22 -0700
Message-ID: <5445bc9f-9d32-9e3e-9fd0-f0e369bbc3f9@aklaver.com> (raw)
In-Reply-To: <87pon9va6n.fsf@otaria.sebmel.org>
References: <87int2qkat.fsf@gmail.com>
	<ff476cf9-beaf-991d-b2ef-cc3aab6d5ac8@aklaver.com>
	<87pon9va6n.fsf@otaria.sebmel.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

On 10/09/2016 08:01 AM, Sebastian P. Luque wrote:
> On Sun, 9 Oct 2016 06:44:10 -0700,
> Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>
> [...]
>
>> Not sure. When I tried using the above(on 9.5) it failed during the
>> CREATE OR REPLACE FUNCTION public.angle_vectors_avg stage with:
>
>> ERROR: type "vector" does not exist
>
>
>> So where is that coming from in your setup?
>
> Aw nuts, I forgot to include that type definition.  Here it is:
>
> CREATE TYPE public.vector AS
>    (angle double precision,
>     magnitude double precision);
> COMMENT ON TYPE public.vector
>   IS 'This type holds the basic descriptors of a vector; namely, angle and magnitude.';
>
>

Hmm:

test=# select version();
                                                            version 

-----------------------------------------------------------------------------------------------------------------------------
  PostgreSQL 9.6.0 on i686-pc-linux-gnu, compiled by gcc (SUSE Linux) 
4.8.3 20140627 [gcc-4_8-branch revision 212064], 32-bit
(1 row)


test=# select avg((random(), random())::angle_vectors);
                  avg
--------------------------------------
  (62.4781575734486,0.865270065328572)

test=# select "time" from generate_series('2016-10-08'::timestamp, 
'2016-10-10'::timestamp, '5 hours') as t("time")
window w as (partition by date_trunc('day', "time") order by "time");
         time
---------------------
  2016-10-08 00:00:00
  2016-10-08 05:00:00
  2016-10-08 10:00:00
  2016-10-08 15:00:00
  2016-10-08 20:00:00
  2016-10-09 01:00:00
  2016-10-09 06:00:00
  2016-10-09 11:00:00
  2016-10-09 16:00:00
  2016-10-09 21:00:00
(10 rows)

test=# SELECT "time", avg(random()) over w
from generate_series('2016-10-08'::timestamp, '2016-10-10'::timestamp, 
'5 hours') as t("time")
window w as (partition by date_trunc('day', "time") order by "time");
         time         |        avg
---------------------+-------------------
  2016-10-08 00:00:00 | 0.387926945462823
  2016-10-08 05:00:00 | 0.649316050112247
  2016-10-08 10:00:00 | 0.608540423369656
  2016-10-08 15:00:00 | 0.561799361603335
  2016-10-08 20:00:00 |  0.54945012088865
  2016-10-09 01:00:00 | 0.130873893853277
  2016-10-09 06:00:00 | 0.443627830361947
  2016-10-09 11:00:00 | 0.314536933631947
  2016-10-09 16:00:00 | 0.425128075061366
  2016-10-09 21:00:00 | 0.385504625830799


test=# SELECT "time", avg((random(), random())::angle_vectors) over w
from generate_series('2016-10-08'::timestamp, '2016-10-10'::timestamp, 
'5 hours') as t("time")
window w as (partition by date_trunc('day', "time") order by "time");
ERROR:  input data type is not an array


The parts work, the whole does not. At this point I have no idea why.

-- 
Adrian Klaver
adrian.klaver@aklaver.com


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



view thread (15+ messages)  latest in thread

Message-ID: <5445bc9f-9d32-9e3e-9fd0-f0e369bbc3f9@aklaver.com>
Permalink:  ../5445bc9f-9d32-9e3e-9fd0-f0e369bbc3f9@aklaver.com/
Also on:    postgresql.org/message-id/5445bc9f-9d32-9e3e-9fd0-f0e369bbc3f9@aklaver.com

 · 

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: adrian.klaver@aklaver.com, spluque@gmail.com
  Subject: Re: custom average window function failure
  In-Reply-To: <5445bc9f-9d32-9e3e-9fd0-f0e369bbc3f9@aklaver.com>
  References: <87int2qkat.fsf@gmail.com> <ff476cf9-beaf-991d-b2ef-cc3aab6d5ac8@aklaver.com> <87pon9va6n.fsf@otaria.sebmel.org> <5445bc9f-9d32-9e3e-9fd0-f0e369bbc3f9@aklaver.com>

* 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