From: | Marc Evans <Marc(at)SoftwareHackery(dot)Com> |
---|---|
To: | Greg Sabino Mullane <greg(at)turnstep(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: printf-like format strings |
Date: | 2007-01-22 19:34:58 |
Message-ID: | 20070122142914.X89713@me.softwarehackery.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I have found the following technique works well for me:
CREATE OR REPLACE FUNCTION audit_log_sprintf(text,integer) RETURNS TEXT as $$
my $fmt = shift;
my $id = shift;
my $msg = spi_exec_query("SELECT array_upper(msg_args,1) FROM audit_logs WHERE id = $id",1);
my $nArgs = $msg->{rows}[0]->{array_upper};
my $i = 1;
my @args;
while ($i <= $nArgs) {
$msg = spi_exec_query("SELECT msg_args[$i] FROM audit_logs WHERE id = $id",1);
push(@args,$msg->{rows}[0]->{msg_args});
$i++;
}
return sprintf $fmt,@args;
$$ LANGUAGE plperl;
The audit_logs table contains at least these columns:
audit_format_id BIGINT NOT NULL,
msg_args TEXT[],
The audit_format_id is a reference into an audit_formats_table of sprintf
format strings. You could easily simplify this to remove that indirection,
if desired.
- Marc
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2007-01-22 19:42:21 | Re: More grist for the PostgreSQL vs MySQL mill |
Previous Message | Kenneth Marshall | 2007-01-22 19:30:28 | Re: [HACKERS] Autovacuum Improvements |