Skip site navigation (1) Skip section navigation (2)

width_bucket() per SQL2003 (WIP)

From: Neil Conway <neilc(at)samurai(dot)com>
To: PostgreSQL-patches (PostgreSQL) <pgsql-patches(at)postgresql(dot)org>
Subject: width_bucket() per SQL2003 (WIP)
Date: 2004-04-25 04:15:16
Message-ID: 2821CCFE-966F-11D8-BDD5-000A95AB279E@samurai.com (view raw or flat)
Thread:
Lists: pgsql-patches
The attached patch implements the width_bucket() function (as specified 
by Section 6.27 of the SQL2003 standard, in particular page 250 in my 
copy). This function accepts an operand, a lower bound, an upper bound, 
and a number of buckets. It returns the number of the bucket to which 
the operand would be assigned in an equidepth histogram with the 
specified characteristics. I believe the function comes from Oracle 9i, 
so you can search the web for more information.

Questions / Issues:

(1) This patch only implements width_bucket() for the 'numeric' type (I 
thought I would get the behaviour right for a single type before 
writing the other variants). What other types should I provide 
implementations for?

(2) SQL2003 says that the fourth argument to the function should be an 
"exact numeric with scale 0" (and the function's return value must have 
the same type). I chose to make this argument an int4 -- does anyone 
think that int2 or int8 would be more appropriate?

This patch includes some basic regression tests for the function, but I 
haven't bothered updating the docs yet -- a subsequent version of this 
patch will do so.

Comments welcome.

-Neil

Attachment: width_bucket-9.patch
Description: application/octet-stream (15.3 KB)

Responses

pgsql-patches by date

Next:From: Neil ConwayDate: 2004-04-25 04:20:01
Subject: Re: Remove traces of xfunc
Previous:From: Alvaro HerreraDate: 2004-04-24 21:58:47
Subject: Remove traces of xfunc

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group