Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 17D2F63264C for ; Sat, 30 Jan 2010 12:33:07 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 47358-02 for ; Sat, 30 Jan 2010 16:32:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f222.google.com (mail-ew0-f222.google.com [209.85.219.222]) by mail.postgresql.org (Postfix) with ESMTP id E85BE632A40 for ; Sat, 30 Jan 2010 12:32:55 -0400 (AST) Received: by ewy22 with SMTP id 22so66053ewy.34 for ; Sat, 30 Jan 2010 08:32:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=W6UI29A2zcGGbGWLQlIsK47w8DunoqXcFy1yTUslAtQ=; b=gjgPAl7djthhqvS1cxW6QkRCA33665trKergcpP65fglopz5kOKfajuludb/wv15N+ JGgNv7fRDV+3qHSUPzZuFZKhkrMOCf25KbfjB8LFbghTD5MS6b9OehdMgOjhazwoYyli vwGulcvBIllIbv1a+RnLNCwZL3G6Y89MgAaMY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=jeP6Iz6s32aQ696YFIBhUu+QQjOBdLD/FKFm/JJ+nztNYIrPFz6BGz6qEAkIKzYwpy dQGV50/3Xjw5ecxDct49vGYVZPvgT707uiqDyi+RsqTq8OfXKuznN/9iYLrr/p1Ei1ZM KOEd9IHVfponC2Y/jy2bctFa1TcUv9+cYvECk= MIME-Version: 1.0 Received: by 10.216.90.70 with SMTP id d48mr1378926wef.159.1264869174677; Sat, 30 Jan 2010 08:32:54 -0800 (PST) In-Reply-To: <3AD82906BF1A43CB940573A88A42C2B3@squarepi.com> References: <4B636022.90804@kickstone.com> <3AD82906BF1A43CB940573A88A42C2B3@squarepi.com> Date: Sat, 30 Jan 2010 09:32:54 -0700 Message-ID: Subject: Re: Partitioning by letter question From: Scott Marlowe To: John Lister Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=AWL=0.039, BAYES_00=-2.599, SUBJECT_FUZZY_TION=0.156 X-Spam-Level: X-Archive-Number: 201001/50 X-Sequence-Number: 33586 On Sat, Jan 30, 2010 at 7:11 AM, John Lister wrote: >> wrote: > > .> Hi, I was wondering if this was possible. I'm trying to partition a > table, > .> which is straightforward enough thanks to the great documentation, but= i >>> >>> have a question: >>> >>> If I partition using something like a product_id for example and have >>> check >>> constraints such as (id>=3D1000 and id<2000) then everything is fine an= d >>> the >>> planner correctly uses the right subset of the tables. However I would >>> like >>> to partition by the first letter and using something like this >>> substr(word,1,1)=3D'a' is ignored by the planner. From reading the docs= I >>> understand that complicated check constraints are ignored, but this >>> doesn't >>> seem overly complicated. >>> >>> Am i doing something wrong or is there another better way to do this > >> Have you tried: > >> (word >=3D 'a' and word <'b') > > Cheers, had my programming head on. One question: > > any ideas about what to put for the last in the list > > i thought something like =A0(word>=3D'z' and word<'{') which is based on = the > ascii ordering. - my db is using utf8 > > I tried to check this by doing > > select * from words where word >'zzzz' order by word limit 10; > > which returns '.' as the first result (ok not a word, but that is a > different issue) but if i do > > select * from words where word <'.' order by word desc limit 10 > > I get '/...' as the first result, I would expect 'zzzz', this doesn't see= m > consistent. Yeah, in non C locales, things like . and " " don't count for ordering. As for the constraints, why not something like: where word < 'a' or word > 'z' Or something like that. Not that I'm not taking upper and lower case into consideration here. you might need something like lower(word) < 'a' etc.