Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TSxyp-00085c-2L for pgsql-sql@postgresql.org; Mon, 29 Oct 2012 22:38:47 +0000 Received: from na3sys009aog103.obsmtp.com ([74.125.149.71]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TSxyn-0007IK-Ic for pgsql-sql@postgresql.org; Mon, 29 Oct 2012 22:38:46 +0000 Received: from mail-qa0-f46.google.com ([209.85.216.46]) (using TLSv1) by na3sys009aob103.postini.com ([74.125.148.12]) with SMTP ID DSNKUI8Fc/XDqLofVyT91+lnZhd2K4kOkJLI@postini.com; Mon, 29 Oct 2012 15:38:45 PDT Received: by mail-qa0-f46.google.com with SMTP id c26so1829515qad.19 for ; Mon, 29 Oct 2012 15:38:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:x-gm-message-state; bh=uX9lk97jxc3BFy1ZRimzlC+fR/IeLuNyiPS66wasvmo=; b=aQCdPSlbfCrk8mlQTY6hUisiSNvcihu0YzBSh7JFpCQIM2kxx9OoIiWk3fefVPJ/+z zsa+Wfd4iCNgL7XN3NulJaARDj5BNUmqvOZZD2ZOtSg8tdy8Jq/laPG+xorpsPrCcTQm vptPr9B85TBEBXUn7/778psGMI1SU9EehWfJhyB0RkoezY7+FXk/51eLIlmNgFD0lMDP NdKd66gxeMmw6nNfz1yg+UA/eNSpxsCGyeEkaJJT5RDThgrroc6Aq+cItMqH+7UuOutD oS/SM4aQtKbywlOxlZFc/h2l/3BQarejQ6dpghjO6/OhMqxNiLeljK73tjRnRyOap0Hy 9JSQ== Received: by 10.49.3.6 with SMTP id 6mr8307327qey.32.1351550323206; Mon, 29 Oct 2012 15:38:43 -0700 (PDT) Received: from [198.206.42.50] (rrcs-24-172-201-241.central.biz.rr.com. [24.172.201.241]) by mx.google.com with ESMTPS id cu14sm2033684qab.1.2012.10.29.15.38.42 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 29 Oct 2012 15:38:42 -0700 (PDT) Message-ID: <508F0576.4020404@noaa.gov> Date: Mon, 29 Oct 2012 18:38:46 -0400 From: Mark Fenbers User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Fun with Dates Content-Type: multipart/mixed; boundary="------------090405050005010407060402" X-Gm-Message-State: ALoCoQlj1CU29jaVCco0RWYWY9XmE46KSso7Ho999NbVW7gi5JRx6LFAgOKZb32sZrU3yoQZ+czJ X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201210/57 X-Sequence-Number: 36928 This is a multi-part message in MIME format. --------------090405050005010407060402 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Greetings,

I want to be able to select all data going back to the beginning of the current month.  The following portion of an SQL does NOT work, but more or less describes what I want...

... WHERE obstime >= NOW() - INTERVAL (SELECT EXTRACT (DAY FROM NOW() ) ) + ' days'

In other words, if today is the 29th of the month, I want to select data that is within 29 days old... WHERE obstime >= NOW() - INTERVAL '29 days'

How do I craft a query to do use a variable day of the month?

Mark
--------------090405050005010407060402 Content-Type: text/x-vcard; charset=utf-8; name="mark_fenbers.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="mark_fenbers.vcf" begin:vcard fn:Mark Fenbers n:Fenbers;Mark org:Ohio River Forecast Center;Hydrometeorological Analysis & Support Unit adr:1901 South OH-134;;National Weather Service;Wilmington;OH;45177-9708;USA email;internet:Mark.Fenbers@noaa.gov title:Senior Meteorologist tel;work:937-383-0430 tel;fax:937-383-0033 url:weather.gov/ohrfc version:2.1 end:vcard --------------090405050005010407060402--