Discussion:
[xquery-talk] XQuery Order By Numerically
jz@uva
2008-02-29 16:29:11 UTC
Permalink
Hi all,

The ORDER BY clause sorts the output alphabetically. However, how do I
sort the output numerically? Is this possible in XQuery?

For example, if the input is = {1, 11, 2, 1234, 4, 123), then the
ORDER BY clause sorts the results as {1, 11, 123, 1234, 2, 4).

How can I sort the results as {1, 2, 4, 11, 123, 1234}?

Thanks!
Michael Kay
2008-02-29 16:39:16 UTC
Permalink
Use

order by xs:integer($x)

Michael Kay
http://www.saxonica.com/
-----Original Message-----
Sent: 29 February 2008 16:29
Cc: Michael Kay
Subject: XQuery Order By Numerically
Hi all,
The ORDER BY clause sorts the output alphabetically. However,
how do I sort the output numerically? Is this possible in XQuery?
For example, if the input is = {1, 11, 2, 1234, 4, 123), then
the ORDER BY clause sorts the results as {1, 11, 123, 1234, 2, 4).
How can I sort the results as {1, 2, 4, 11, 123, 1234}?
Thanks!
赵雷
2008-02-29 16:52:44 UTC
Permalink
What implementation are you using?

I use xqilla2, it works in the way you expect.

for $i in (1, 11, 2, 1234, 4, 123)
order by $i
return $i

/home/chuck/temp $ xqilla2 a.xq
1
2
4
11
123
1234
Post by ***@uva
Hi all,
The ORDER BY clause sorts the output alphabetically. However, how do I
sort the output numerically? Is this possible in XQuery?
For example, if the input is = {1, 11, 2, 1234, 4, 123), then the
ORDER BY clause sorts the results as {1, 11, 123, 1234, 2, 4).
How can I sort the results as {1, 2, 4, 11, 123, 1234}?
Thanks!
_______________________________________________
http://x-query.com/mailman/listinfo/talk
jz@uva
2008-02-29 17:01:24 UTC
Permalink
Hi,
Thank you. I am now using MonetDB4 and Pathfinder/PF/Tijah, and itdoes not work at all.
There is an ORDER BY, but it orders alphabetically. When I put thevariable between xs:integer, I get the error "reference to undefinedfunction `xs:integer'".
It's amazing that there are so many implementations doing differentthings (or not doing)...
If anyone knows an other way to achieve this, please let me know.
Thanks!
On Fri, Feb 29, 2008 at 5:52 PM, 赵雷 <***@gmail.com> wrote:> What implementation are you using?>> I use xqilla2, it works in the way you expect.>> for $i in (1, 11, 2, 1234, 4, 123)> order by $i> return $i>> /home/chuck/temp $ xqilla2 a.xq>> 1> 2> 4> 11> 123> 1234>>>> On 3/1/08, ***@uva <***@gmail.com> wrote:> > Hi all,> >> > The ORDER BY clause sorts the output alphabetically. However, how do I> > sort the output numerically? Is this possible in XQuery?> >> > For example, if the input is = {1, 11, 2, 1234, 4, 123), then the> > ORDER BY clause sorts the results as {1, 11, 123, 1234, 2, 4).> >> > How can I sort the results as {1, 2, 4, 11, 123, 1234}?> >> > Thanks!> > _______________________________________________> > ***@x-query.com> > http://x-query.com/mailman/listinfo/talk> >>
jz@uva
2008-02-29 17:12:10 UTC
Permalink
Hi all,
I got it working with the XPath2.0 function fn:number, seehttp://www.w3.org/TR/xpath-functions/#func-number
Thanks for all your help though! :)
2008/2/29 ***@uva <***@gmail.com>:> Hi,>> Thank you. I am now using MonetDB4 and Pathfinder/PF/Tijah, and it> does not work at all.>> There is an ORDER BY, but it orders alphabetically. When I put the> variable between xs:integer, I get the error "reference to undefined> function `xs:integer'".>> It's amazing that there are so many implementations doing different> things (or not doing)...>> If anyone knows an other way to achieve this, please let me know.>> Thanks!>>>> On Fri, Feb 29, 2008 at 5:52 PM, 赵雷 <***@gmail.com> wrote:> > What implementation are you using?> >> > I use xqilla2, it works in the way you expect.> >> > for $i in (1, 11, 2, 1234, 4, 123)> > order by $i> > return $i> >> > /home/chuck/temp $ xqilla2 a.xq> >> > 1> > 2> > 4> > 11> > 123> > 1234> >> >> >> > On 3/1/08, ***@uva <***@gmail.com> wrote:> > > Hi all,> > >> > > The ORDER BY clause sorts the output alphabetically. However, how do I> > > sort the output numerically? Is this possible in XQuery?> > >> > > For example, if the input is = {1, 11, 2, 1234, 4, 123), then the> > > ORDER BY clause sorts the results as {1, 11, 123, 1234, 2, 4).> > >> > > How can I sort the results as {1, 2, 4, 11, 123, 1234}?> > >> > > Thanks!> > > _______________________________________________> > > ***@x-query.com> > > http://x-query.com/mailman/listinfo/talk> > >> >>
Torsten Grust
2008-02-29 17:18:46 UTC
Permalink
Hi,

it'd help if you could show your (failing) example. In the
meantime, for Pathfinder please replace xs:integer($x) by
$x cast as xs:integer. Sorry for the hassle. We're working
on it.

Hope this helps,
--Torsten (Pathfinder team, TU Munich)
Post by ***@uva
Hi,
Thank you. I am now using MonetDB4 and Pathfinder/PF/Tijah, and itdoes not work at all.
There is an ORDER BY, but it orders alphabetically. When I put
thevariable between xs:integer, I get the error "reference to
undefinedfunction `xs:integer'".
It's amazing that there are so many implementations doing
differentthings (or not doing)...
If anyone knows an other way to achieve this, please let me know.
Thanks!
What implementation are you using?>> I use xqilla2, it works in the
way you expect.>> for $i in (1, 11, 2, 1234, 4, 123)> order by
$i> return $i>> /home/chuck/temp $ xqilla2 a.xq>> 1> 2> 4> 11>
Hi all,> >> > The ORDER BY clause sorts the output
alphabetically. However, how do I> > sort the output numerically?
Is this possible in XQuery?> >> > For example, if the input is =
{1, 11, 2, 1234, 4, 123), then the> > ORDER BY clause sorts the
results as {1, 11, 123, 1234, 2, 4).> >> > How can I sort the
results as {1, 2, 4, 11, 123, 1234}?> >> > Thanks!> >
query.com> > http://x-query.com/mailman/listinfo/talk> >>
_______________________________________________
http://x-query.com/mailman/listinfo/talk
--
| Prof. Dr. Torsten Grust ***@in.tum.de |
| http://www-db.in.tum.de/~grust/ |
| Database Systems - Technische Universität München (Germany) |
Loading...