Re: creating a function with another function - Mailing list pgsql-general

From Dave Huber
Subject Re: creating a function with another function
Date
Msg-id 7CDADB576E07AC4FA71E1B12566C9126540E0A0C37@lti-mb-1.LTI.com
Whole thread Raw
In response to Re: creating a function with another function  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: creating a function with another function
List 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
last10 million. I already need to setup a trigger function for inserting into the latest partition. What I'd like to do
isautomate the process of creating a new table with a name based off the record ID, a bigserial that is used to
definingeach 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
thatcan occur at different intervals of time. Also, the application starts and stops at various times, so it must be
ableto 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
thepartitions log_1, log_2, ..., log_x, where x is the record ID / 100000. I would also have to be able to truncate the
sameway, 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
inerror, 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
similarimport, absent an express statement to the contrary contained in this e-mail, neither this e-mail nor any
attachmentsare 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
companycannot accept responsibility for any loss or damage arising from the use of this email or attachments. 


pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: creating a function with another function
Next
From: David Fetter
Date:
Subject: Re: creating a function with another function