Search Postgresql Archives

Re: Selecting pairs of numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When in doubt, cheat! Why not something like:

SELECT x, y FROM organ_pipes WHERE point(x,y) <@ box(point(?x1,?y1),point(?x2,?y2)) ;

This is definitely a different approach from the others that I've seen.


Basically, think of your channel / piston as a point in a Cartesian plane. And your boundaries as a box in that graph. So you see if the "point" is inside the "box"

On Mon, Oct 5, 2015 at 1:39 PM, Raymond O'Donnell <rod@xxxxxx> wrote:
Hello all,

I have an SQL problem which ought to be simple, but I can't get my head
around it.

I have pairs of integers - let's call them (x, y). In effect, x is a
category, while y is an item within that category. For every x, there is
always the same number of integers y; and both x and y are always
numbered sequentially starting from 1.

My problem is that I need to select a list of these pairs, ordered first
on x and then on y, from a given starting point to a given finishing
point and including all pairs in between.

For example, I might have:

x | y
-----
1 | 1
1 | 2
1 | 3
1 | 4
2 | 1
2 | 2
2 | 3
2 | 4
(etc)

I then might want to extract a list from, say, (1, 3) to (3, 2), giving:

x | y
-----
1 | 3
1 | 4
2 | 1
2 | 2
2 | 3
2 | 4
3 | 1
3 | 2

For the life of me, I can't figure out how to do this. Any help will be
appreciated, or even just a pointer in the right direction. There's
probably something simple that I'm just not seeing....

If anyone's interested, these numbers represent channels and pistons on
the combination system of a largish pipe organ... it's for a hobby project.

Many thanks in advance!

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@xxxxxx


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



--

Schrodinger's backup: The condition of any backup is unknown until a restore is attempted.

Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be.

He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux