> 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.


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to