pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Add: Special sort querstion
3+ messages / 2 participants
[nested] [flat]

* Re: Add: Special sort querstion
@ 2009-04-01 14:57  Dirk Jagdmann <jagdmann@gmail.com>
  2 siblings, 0 replies; 3+ messages in thread

From: Dirk Jagdmann @ 2009-04-01 14:57 UTC (permalink / raw)
  To: d.piekarski@vivawasser.de; +Cc: pgsql-sql

I think it can not be done with default PostgreSQL functions and
operators, because you must compare two different columns of two rows
depending which row is on either side of the "<" comparision.

But I think you can do this with the following steps:

1) create a new type as a 4-tupel of start_lat, end_lat, start_lng, end_lng.
2) write a comparison function for this type
3) write a SQL-Function to convert 4 values into your new type (for
example: ToMyType(start_lat, end_lat, start_lnd, end_lng) returns
MyType...)
4) use ToMyType in the order clause of your select

If this would work, I'm interested in a working example code :-)

-- 
---> Dirk Jagdmann
----> http://cubic.org/~doj
-----> http://llg.cubic.org



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

* Re: Add: Special sort querstion
@ 2009-04-01 14:57  Dirk Jagdmann <jagdmann@gmail.com>
  2 siblings, 0 replies; 3+ messages in thread

From: Dirk Jagdmann @ 2009-04-01 14:57 UTC (permalink / raw)
  To: d.piekarski@vivawasser.de; +Cc: pgsql-sql

I think it can not be done with default PostgreSQL functions and
operators, because you must compare two different columns of two rows
depending which row is on either side of the "<" comparision.

But I think you can do this with the following steps:

1) create a new type as a 4-tupel of start_lat, end_lat, start_lng, end_lng.
2) write a comparison function for this type
3) write a SQL-Function to convert 4 values into your new type (for
example: ToMyType(start_lat, end_lat, start_lnd, end_lng) returns
MyType...)
4) use ToMyType in the order clause of your select

If this would work, I'm interested in a working example code :-)

-- 
---> Dirk Jagdmann
----> http://cubic.org/~doj
-----> http://llg.cubic.org



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

* Re: Add: Special sort querstion
@ 2009-04-01 15:08  Scott Marlowe <scott.marlowe@gmail.com>
  2 siblings, 0 replies; 3+ messages in thread

From: Scott Marlowe @ 2009-04-01 15:08 UTC (permalink / raw)
  To: d.piekarski@vivawasser.de; +Cc: pgsql-sql

On Fri, Mar 27, 2009 at 6:10 AM, Dominik Piekarski
<d.piekarski@vivawasser.de> wrote:
> Oh, actually every row of the same id-range has the same start_lat/start_lng
> coordinates as the predecessors end_lat/end_lng coordinates. But the
> question remains the same. Is there a way to do something like ORDER BY
> (start_lat = end_lat AND start_lng = end_lng) ? Or maybe another way to
> achieve the same result?

Would something like

order by start_lat-endlat, start_lng-end_lng

OR

case when start_lat=end_lat AND start_lng=end_lng then 0 else 1 end

???



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


end of thread, other threads:[~2009-04-01 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-04-01 14:57 ` Dirk Jagdmann <jagdmann@gmail.com>
2009-04-01 14:57 ` Dirk Jagdmann <jagdmann@gmail.com>
2009-04-01 15:08 ` Scott Marlowe <scott.marlowe@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