Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 8FA9E1337B82 for ; Mon, 21 Mar 2011 06:29:27 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 81831-05 for ; Mon, 21 Mar 2011 09:29:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ey0-f174.google.com (mail-ey0-f174.google.com [209.85.215.174]) by mail.postgresql.org (Postfix) with ESMTP id B3AB81337B58 for ; Mon, 21 Mar 2011 06:29:19 -0300 (ADT) Received: by eyx24 with SMTP id 24so1447174eyx.19 for ; Mon, 21 Mar 2011 02:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:content-type:content-transfer-encoding; bh=zUxeUlwAjCDfrYVKXxMZjA6gq3n11sLTTX60WwdBXdg=; b=KT28n1Xy4pXS7OwNtmzqP5sblJEcYSp0XWMgQOzlEYHXpQz2z+rxNJHSopVjDVYySb Nls+kqtdPbEWBIA8mnXoR/ZaG7f8BEm4+a1HaNLRFZctE5iMg+PkV58zzhNPcHiw8sjY 1OlBGuxbycAx5y3wPogJ7xkwG2yCILN6H82XI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=qb2Gp/NCoqlqCM46wGDwlC3sWsa631NU4Wyb25gzeghx9DXyWMPsxjD22HWUGZHOmH 6O6GvQ15fBq/XK+G8/faVqT8LwsJ3YOFLO+mseFEyBPPHWGKTyB46v4QqnT2/jZ5vxT8 ccUkynBwYxztgnXpd/y8vbxn+z9/j4DwwmNGo= Received: by 10.213.32.137 with SMTP id c9mr1664910ebd.114.1300699758730; Mon, 21 Mar 2011 02:29:18 -0700 (PDT) Received: from [192.168.112.20] (22.255.196.88.sta.estpak.ee [88.196.255.22]) by mx.google.com with ESMTPS id x54sm1771547eeh.12.2011.03.21.02.29.17 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 21 Mar 2011 02:29:17 -0700 (PDT) Message-ID: <4D871A6E.6050608@gmail.com> Date: Mon, 21 Mar 2011 11:29:18 +0200 From: Tambet Matiisen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Obscure behavior of ORDER BY Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.589 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201103/33 X-Sequence-Number: 35235 Hi everyone! I recently noticed obscure behavior of ORDER BY. Consider this example: select email from ( select '@'::text as email union all select '.'::text as email ) a order by email; The result is: email ------- . @ (2 rows) This is all normal - I expect, that dot is smaller than ampersand. But if I add anything after dot, the order is reversed: select email from ( select '@'::text as email union all select '.m'::text as email ) a order by email The result is: email ------- @ .m (2 rows) Why is this happening? As dot is smaller than ampersand, anything after dot shouldn't matter. I'm using PostgreSQL 8.4.7 on 32-bit Debian. Thanks in advance, Tambet