Skip site navigation (1) Skip section navigation (2)

Re: compare table names

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Tony Capobianco <tcapobianco(at)prospectiv(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: compare table names
Date: 2012-01-09 16:58:18
Message-ID: 4F0B1CAA.2060604@pinpointresearch.com (view raw or flat)
Thread:
Lists: pgsql-sql
On 01/09/2012 08:28 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?
>
> Thanks.
> Tony
...Ah, there's the missing part - the 1229 represents a date that is 
missing year information.

If you can change things up a bit, I'd add the year to the name 
"tmp_stagingYYYYMMDD" which makes the query easy. (We do this in a few 
cases where we are given blocks of data that are valid through a certain 
date. Each block of data is a child of the main table and has a name 
that represents the last date the data is valid. A daily script drops 
any partition that has expired.)

If you can't add the year, you will be stuck with extra work to properly 
handle the first 10-days of each year.

Alternately, you could have a separate table that just tracks the 
creation dates of the temporary tables and be free from any requirement 
to have dates be part of the table names.

Cheers,
Steve


In response to

pgsql-sql by date

Next:From: Adrian KlaverDate: 2012-01-09 16:58:49
Subject: Re: compare table names
Previous:From: Greg Sabino MullaneDate: 2012-01-09 16:51:30
Subject: Re: compare table names

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group