Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 72409AF82E9 for ; Mon, 9 Jan 2012 12:59:09 -0400 (AST) Received: from mail-tul01m020-f174.google.com ([209.85.214.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RkIYv-0001Rq-7c for pgsql-sql@postgresql.org; Mon, 09 Jan 2012 16:59:09 +0000 Received: by obcwo16 with SMTP id wo16so4329279obc.19 for ; Mon, 09 Jan 2012 08:58:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=o3i752O2s5Cju8MpSqCdwJt1ifhmRC4Q4lZ1e/sRwnI=; b=mpTdcdamTsqwr/pFMDMHx7TRWYDeUo/WEG/k6M5dkxkT9RGmbm91asWkKquybMvf52 hF+o1MCOApNHaRSNoOJSzrfAPIBXlaqtltlHcqfMmarxQj4sG2JM2VOtMVC8X9YnNa7u jQKnPIhCGFYPOabte7fVDDpt1z0gJv+rfo9Lk= Received: by 10.182.162.70 with SMTP id xy6mr15408135obb.53.1326128335631; Mon, 09 Jan 2012 08:58:55 -0800 (PST) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net. [24.17.164.54]) by mx.google.com with ESMTPS id m2sm4332311obu.3.2012.01.09.08.58.53 (version=SSLv3 cipher=OTHER); Mon, 09 Jan 2012 08:58:54 -0800 (PST) From: Adrian Klaver To: Tony Capobianco Subject: Re: compare table names Date: Mon, 9 Jan 2012 08:58:49 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.32-37-generic; KDE/4.4.5; i686; ; ) Cc: pgsql-sql@postgresql.org References: <1326125538.1983.12.camel@tony1.localdomain> <201201090819.48041.adrian.klaver@gmail.com> <1326126523.1983.16.camel@tony1.localdomain> In-Reply-To: <1326126523.1983.16.camel@tony1.localdomain> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201201090858.49838.adrian.klaver@gmail.com> X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201201/34 X-Sequence-Number: 36205 On Monday, January 09, 2012 8:28:43 am Tony Capobianco wrote: > I see what you're saying: > > pg=# select tablename from pg_tables where tablename like 'tmp_staging%' > and tablename < 'tmp_staging1230' and tablename > 'tmp_staging1228'; > tablename > -------------------- > tmp_staging1229 > > > This query is part of a larger script where I want to dynamically select > tablenames older than 10 days and drop them. The tables are created in > a tmp_stagingMMDD format. I know postgres does not maintain object > create times, how can I write this to select tables from pg_tables that > are older than 10 days? Well with out a year number(i.e. YYMMDD) that is going to be difficult around the year break. As an example: test(5432)aklaver=>select * from name_test; fld_1 ----------------- tmp_staging0109 tmp_staging0108 tmp_staging1229 (3 rows) test(5432)aklaver=>SELECT fld_1 from name_test where fld_1 < 'tmp_staging'|| to_char(current_date-interval '10 days','MMDD') and fld_1 > 'tmp_staging0131'; fld_1 ----------------- tmp_staging1229 > > Thanks. > Tony > -- Adrian Klaver adrian.klaver@gmail.com