Name: Alvaro Herrera
Member since: 2005-03-28 04:09:29
Last Login: 2010-05-13 14:53:37
Homepage: http://alvherre.cl
Notes: PostgreSQL developer
I will be obviously unable to work much on patches, or anything really, for at least a week ...
10 Sep 2009 (updated 10 Sep 2009 at 16:06 UTC) »
Se acaba de publicar una nueva serie de versiones
actualizadas de PostgreSQL para todas las ramas soportadas,
desde 7.4 hasta 8.4. El anuncio en español
apareció, entre otros, en postgresql.cl.
(Y este es el
anuncio oficial en la lista pgsql-announce). Se
recomienda a todos actualizar a esta
versión.
Y recuerden que para Windows
sólo están soportadas las ramas 8.2, 8.3 y
8.4. En las nuevas versiones se corrigió finalmente
el problema que daba lugar al error “could not
reattach to shared memory”, así que los
usuarios de Windows son los que estarán más
contentos.
Disfruten.
14 Jul 2009 (updated 14 Jul 2009 at 22:24 UTC) »
sprintf in SQL
Ever needed to print out something with embedded data? Not an uncommon requirement, I'm afraid. Most people just concatenate stuff together:
SELECT 'A number ' || 42 || ' is a ' || 21 || ' * ' || 2 || ' by any other name'
Eventually it turns out confusing, as it's easy to visually mix the concatenation operator || with the quotes.
PL/pgSQL offers a printf of sorts ... except that you can't use it everywhere you'd like:
RAISE NOTICE ' A number % is a % * % by any other name', 42, 21, 2;
CREATE OR REPLACE FUNCTION printf(fmt text, variadic args anyarray) returns text
language plpgsql AS $$
DECLARE
argcnt int = 1;
chrcnt int = 0;
fmtlen int;
CHR text;
output text = '';
BEGIN
fmtlen = LENGTH(fmt);
LOOP
chrcnt = chrcnt + 1;
-- ran out of format string? bail out
IF chrcnt > fmtlen THEN
EXIT;
END IF;
-- grab our char
CHR = substring(fmt, chrcnt, 1);
-- %% means output a single %, and skip them
IF CHR = '%' AND substring(fmt, chrcnt + 1, 1) = '%' THEN
output = output || '%';
chrcnt = chrcnt + 1;
continue;
END IF;
-- a % on its own means output an element from our arg list
IF CHR = '%' THEN
output = output || COALESCE(args[argcnt]::text, '');
argcnt = argcnt + 1;
continue;
END IF;
-- no special case? output the thing
output = output || CHR;
END LOOP;
RETURN output;
END;
$$;
# select printf('% is a % and % is a %, but %% is a %',
'hello', 'word', 1::text, 'number', 'percent sign');
printf
------------------------------------------------------------
hello is a word and 1 is a number, but % is a percent sign
(1 fila)
alvherre=# select printf('% %% is %',
3.01110001100101::float::numeric(10,2)::text,
ROW(1,2,3,'foo bar')::text);
printf
-----------------------------
3.01 % is (1,2,3,"foo bar")
(1 fila)
What I do instead is have these lines in .mutt/muttrc:
# Useful macros for Majordomo list administration macro pager R "|~/bin/majordomo-reject\nd" "Majordomo reject" macro pager A "|~/bin/majordomo-accept\nd" "Majordomo accept"
And then majordomo-accept and majordomo-reject are symlinks to a Perl program that looks like this:
#!/usr/bin/perl
use warnings; use Net::SMTP;
if ($0 =~ /accept/) { $action = "accept"; $fullaction = "Accepting"; } elsif ($0 =~ /reject/) { $action = "reject-quiet"; $fullaction = "Rejecting"; }
die "No mode defined" unless defined $action;
while (<>) { if (/^Subject: ([0-9A-Z-]{14}) : (CONSULT|REMINDER)/) { $token = $1; last; } }
die "No token defined" unless defined $token;
$smtp = Net::SMTP->new('localhost') or die "new: $!";
$smtp->mail('alvherre@surnet.cl'); $smtp->to('majordomo@postgresql.org');
$smtp->data; $smtp->datasend(<<END_OF_MAIL); From: Moderation Robot <alvherre\@alvh.no-ip.org> To: postgresql.org's Majordomo <majordomo\@postgresql.org> Subject: $fullaction token $token
$action $token END_OF_MAIL $smtp->dataend(); $smtp->quit;
The main upside to this approach is that I don't have to hit "reply" to the email; I can just hit "R" or "A" on the mutt message view.
alvherre certified others as follows:
Others have certified alvherre as follows:
[ Certification disabled because you're not logged in. ]
FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.
Keep up with the latest Advogato features by reading the Advogato status blog.
If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!