Re: sorting db queries

2011-05-23 Thread Edwin Eyan Moragas
Hi Alex,

thank you. just what i need.

/e

On Tue, May 24, 2011 at 2:09 AM, Alexander Burger  wrote:
> Hi Edwin,
>
>> i'm trying to look for an example of sorting the output of database
>> queries by a given attribute.
>> ...
>> (class +MyClass +Entity)
>> (rel date (+Date))
>> ...
>> and if i run a query, i'd like to sort the output, say, by increasing date.
>
> There are two possibilities:
>
> 1. If this sorting is often necessary, you maintain an index for that
>   attribute:
>
>      (rel date (+Ref +Date))
>
>   Then all queries on that attribute will directly return sorted
>   results:
>
>      (collect 'date '+MyClass)
>      (collect 'date '+MyClass  )
>
>      (pilog '((db date +MyClass @M) ...) ...)
>
>   Note, however, if 'select' is used with multiple search attributes,
>   the resulting order is not defined.
>
>
> 2. If you need to do that only once or seldom, sort the results after
>   fetching them:
>
>   (by '((This) (: date)) sort
>      (collect 'someOtherAttribute '+MyClass) )
>
>   This has the disadvantage that first all results must be fetched, of
>   course, before they can be sorted.
>
> Cheers,
> - Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: sorting db queries

2011-05-23 Thread Alexander Burger
Hi Edwin,

> i'm trying to look for an example of sorting the output of database
> queries by a given attribute.
> ...
> (class +MyClass +Entity)
> (rel date (+Date))
> ...
> and if i run a query, i'd like to sort the output, say, by increasing date.

There are two possibilities:

1. If this sorting is often necessary, you maintain an index for that
   attribute:

  (rel date (+Ref +Date))

   Then all queries on that attribute will directly return sorted
   results:

  (collect 'date '+MyClass)
  (collect 'date '+MyClass  )

  (pilog '((db date +MyClass @M) ...) ...)

   Note, however, if 'select' is used with multiple search attributes,
   the resulting order is not defined.


2. If you need to do that only once or seldom, sort the results after
   fetching them:

   (by '((This) (: date)) sort
  (collect 'someOtherAttribute '+MyClass) )

   This has the disadvantage that first all results must be fetched, of
   course, before they can be sorted.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


sorting db queries

2011-05-23 Thread Edwin Eyan Moragas
Hi list,

i'm currently playing with pilog and the database.

i'm trying to look for an example of sorting the output of database
queries by a given attribute.

as a trivial example:

(class +MyClass +Entity)
(rel date (+Date))

and if i run a query, i'd like to sort the output, say, by increasing date.

sorry if i missed this somewhere.

/e
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe