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

Re: compare table names

From: Tony Capobianco <tcapobianco(at)prospectiv(dot)com>
To: Brice André <brice(at)famille-andre(dot)be>
Cc: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: compare table names
Date: 2012-01-11 14:29:04
Message-ID: 1326292144.1988.1.camel@tony1.localdomain (view raw or flat)
Thread:
Lists: pgsql-sql
This is an old system that we converted over from Oracle just this past
year.  The first 10 days of this year bit us when needed warehouse
tables were removed erroneously.
I'm going to push uphill against management to try and create the tables
as table_nameYYYYMMDD.
Wish me luck!

Thanks for all your responses.

Tony


On Wed, 2012-01-11 at 07:43 +0100, Brice André wrote:
> Just my 2 cents...
> 
> Why don't you use a date column type instead of a string ? In this
> case, at insertion, you could simply do this : 
> 
> INERT INTO tablename (insertion_time, ...) VALUES (now(), ...)
> 
> and, for the select, you could simply write :
> 
> SELECT * FROM tablename WHERE insertion_time >= (now() - interval '1
> day')
> 
> 
> 
> 2012/1/9 Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
>         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(dot)klaver(at)gmail(dot)com
>         
>         
>         
>         --
>         Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
>         To make changes to your subscription:
>         http://www.postgresql.org/mailpref/pgsql-sql
>         
> 



In response to

pgsql-sql by date

Next:From: Gerardo HerzigDate: 2012-01-11 15:36:32
Subject: amount of join's and sequential access to the tables involved
Previous:From: Brice AndréDate: 2012-01-11 06:43:10
Subject: Re: compare table names

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