Re: Is there a way to build a query based on data in a table?

From: Brice André <brice(at)famille-andre(dot)be>
To: Herouth Maoz <herouth(at)unicell(dot)co(dot)il>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Is there a way to build a query based on data in a table?
Date: 2013-08-28 10:45:06
Message-ID: CAOBG12m8Yy24=NAZuZwWG+YwoSLVv3HNv6raj3w__09F4FcG1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

From what I know, in pure SQL, it is not possible to perform what you want.

But it is feasible in PL/pgSQL (and this script language is supported
by default by postgresql...).

Regards,
Brice

2013/8/28 Herouth Maoz <herouth(at)unicell(dot)co(dot)il>:
> Hello.
>
> I want to run an automatic archiving SQL script, that looks at a meta-table
> containing data about the tables to be archived.
>
> Basically, suppose I have this data in the meta-table:
>
> table_name varchar(100)
> datetime_column_name varchar(100)
> archive_interval interval
>
> Like this:
> public.foo | foo_date | 1 day
> schema1.bar | bar_time | 2 day
>
> And for each such table I want to run a query like
>
> INSERT INTO foo__archive
> SELECT * FROM foo
> WHERE foo_date < timestamp 'today' - interval '1 day'
> ;
>
> And I want to build this dynamically and run it based on the table above. Is
> there any way of doing this? I mean, not by doing text manipulation in a
> programming language?
>
>
>
>
>
> Herouth

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Charles Sheridan 2013-08-28 15:08:12 CTAGS for PL/pgSQL ?
Previous Message Herouth Maoz 2013-08-28 10:07:18 Is there a way to build a query based on data in a table?