Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 307119FB942 for ; Fri, 20 Apr 2007 13:33:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 62808-04 for ; Fri, 20 Apr 2007 13:33:31 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.242]) by postgresql.org (Postfix) with ESMTP id 5C2789FB89C for ; Fri, 20 Apr 2007 13:33:31 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c24so1019262ana for ; Fri, 20 Apr 2007 09:33:30 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=QL+gHbI4TOdhkUh8EqP+EAzkG6SWjQRQDGL40WEj/SJRgkGcDC0y7Kp8ZkD0SvrWUWYeYrPDlC54LRT3b/WeaAgYyDbpEtbLA17L5r18Y1A1n3zF67zV5oKQuIoRVonz1vAhtA4LhGCSpTjgJdPfkLXOz7zFHV4tdVYaxivJnp8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ukKjShu+ZuUqbTy7WD9+jUS/VuA2tocYm5VkI43HRS2owd+mF+KrsYctcKCkRK7V0HxQRBGb6BFHvZJosvB7zEi/EACbyncjh2UKdFaNlBO7jJ6qDBhBH+uzSjwpGBUSiH7CVYZtSQ/jn91x8BUZWe8yj1sWh1eInOJYRN7fgbc= Received: by 10.100.167.7 with SMTP id p7mr1808432ane.1177086810488; Fri, 20 Apr 2007 09:33:30 -0700 (PDT) Received: by 10.100.154.9 with HTTP; Fri, 20 Apr 2007 09:33:30 -0700 (PDT) Message-ID: Date: Fri, 20 Apr 2007 11:33:30 -0500 From: "=?ISO-8859-1?Q?Rodrigo_De_Le=F3n?=" To: pgsql-sql@postgresql.org Subject: Re: Retrieve month from date Cc: RPK In-Reply-To: <10105471.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <11604f180704200519h5d858f6ey1efbbccd52ccd0c9@mail.gmail.com> <10105471.post@talk.nabble.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/191 X-Sequence-Number: 28191 On 4/20/07, RPK wrote: > > Thanks both of you, > > I ran EXPLAIN command on above suggested query and got following result: > > "Aggregate (cost=2.77..2.79 rows=1 width=10)" > " -> Seq Scan on studentfeespayment (cost=0.00..2.77 rows=1 width=10)" > " Filter: (date_part('month'::text, (recieptmonthyear)::timestamp > without time zone) = 4::double precision)" > > What does this mean? Can I optimize it better? create index lala on "StudentFeesPayment"(Extract(Month from "ReceiptMonthYear")) explain Select max("ReceiptNo") from "StudentFeesPayment" where Extract(Month from "ReceiptMonthYear")=4; Aggregate (cost=14.97..14.98 rows=1 width=4) -> Bitmap Heap Scan on "StudentFeesPayment" (cost=4.33..14.94 rows=10 width=4) Recheck Cond: (date_part('month'::text, ("ReceiptMonthYear")::timestamp without time zone) = 4::double precision) -> Bitmap Index Scan on lala (cost=0.00..4.33 rows=10 width=0) Index Cond: (date_part('month'::text, ("ReceiptMonthYear")::timestamp without time zone) = 4::double precision) See: http://www.postgresql.org/docs/8.2/static/indexes-expressional.html