Re: creating a function with another function

From: Dave Huber <DHuber(at)letourneautechnologies(dot)com>
To: 'Merlin Moncure' <mmoncure(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: creating a function with another function
Date: 2009-10-12 20:36:47
Message-ID: 7CDADB576E07AC4FA71E1B12566C9126540E0A0C37@lti-mb-1.LTI.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Surely, there are valid cases of having a function create a function.
> Suppose (just off the top of my head), you create a helper function
> that generates triggers on a table for record archiving.

My application is for archiving. I'm using partitioned tables (each 100000 records) to keep a rolling archive of the last 10 million. I already need to setup a trigger function for inserting into the latest partition. What I'd like to do is automate the process of creating a new table with a name based off the record ID, a bigserial that is used to defining each partition. Whether its automated or not, every 100000 record inserts will require 3 actions:

1. create a new partition,
2. modify the insert trigger function, and
3. truncate and drop the oldest partition.

A number of things complicate the process for me. I'm using a COPY statement to bulk insert a varying number of records that can occur at different intervals of time. Also, the application starts and stops at various times, so it must be able to initialize based on the state of the database on startup.

Is there a way to dynamically create table names within a function based on a numeric value? I want to be able to name the partitions log_1, log_2, ..., log_x, where x is the record ID / 100000. I would also have to be able to truncate the same way, by dynamically specifying the name of the table to be deleted.

Well, I appreciate the help, anyway.

Thanks,
Dave

This electronic mail message is intended exclusively for the individual(s) or entity to which it is addressed. This message, together with any attachment, is confidential and may contain privileged information. Any unauthorized review, use, printing, retaining, copying, disclosure or distribution is strictly prohibited. If you have received this message in error, please immediately advise the sender by reply email message to the sender and delete all copies of this message.
THIS E-MAIL IS NOT AN OFFER OR ACCEPTANCE: Notwithstanding the Uniform Electronic Transactions Act or any other law of similar import, absent an express statement to the contrary contained in this e-mail, neither this e-mail nor any attachments are an offer or acceptance to enter into a contract, and are not intended to bind the sender, LeTourneau Technologies, Inc., or any of its subsidiaries, affiliates, or any other person or entity.
WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2009-10-12 21:13:23 Re: creating a function with another function
Previous Message Merlin Moncure 2009-10-12 19:54:31 Re: creating a function with another function