2017-03-03 9 views
1

私はpostgresqlのテーブルのテーブル作成時間を見つけることができません(PostgreSQL: Table creation time)。私はまだテーブルのプロキシを得ることが大好きです特定の日付の後に作成されたものです。私のデータベースのほとんどのテーブルにはcreated_atの日付があります。テーブルごとにテーブルをクエリすることなく、min(created_at)の日付が> xのテーブルをすべてのテーブルでチェックする方法はありますか?postgresqlデータベースのすべてのテーブルの分(created_at)を見つける

+0

この投稿には、あなたが求めている情報があるようです。 http://stackoverflow.com/questions/5350088/how-to-search-a-specific-value-in-all-tables-postgresql –

答えて

0

免責事項:実際に、それは全体の質問への答えではないだけので

に、私は今、私はPostgreSQLの癆

用テーブル作成時間を見つけることができないことを知っています

はい、あなたはevent triggersを使って自分でこのようなデータを収集することができます。

/* 
drop table if exists t1; 
drop table if exists public.t2; 
drop event trigger if exists tg_table_created_at; 
drop function if exists fn_table_created_at(); 
drop table if exists table_created_at; 
*/  

create table table_created_at(
    toid oid, 
    tname text, 
    created_at timestamptz default clock_timestamp()); 

create function fn_table_created_at() 
    returns event_trigger 
    language plpgsql 
    as $$ 
begin 
    insert into table_created_at(toid, tname) 
    select objid, object_identity 
    from pg_event_trigger_ddl_commands() 
    where command_tag = 'CREATE TABLE'; 
end $$; 

create event trigger tg_table_created_at on ddl_command_end 
    execute procedure fn_table_created_at(); 

create temp table t1(); 
select pg_sleep(1); 
create table public.t2(); 

select *, toid::regclass from table_created_at; 

結果:

 
╔═══════╤════════════╤═══════════════════════════════╤══════════════╗ 
║ toid │ tname │   created_at   │  toid  ║ 
╠═══════╪════════════╪═══════════════════════════════╪══════════════╣ 
║ 87803 │ pg_temp.t1 │ 2017-03-03 20:05:44.339811+02 │ pg_temp_3.t1 ║ 
║ 87806 │ public.t2 │ 2017-03-03 20:05:45.344503+02 │ public.t2 ║ 
╚═══════╧════════════╧═══════════════════════════════╧══════════════╝ 

そして、いくつかの追加のリンク:Event Trigger FunctionsEvent Trigger Firing MatrixObject Identifier Types

は例があります。

関連する問題