Hello!
I found a funny bug in postgres with c functions. (or feature??)
Let's say we have got an function like this:
CREATE FUNCTION hupper(text)
RETURNS text
AS '/fun.so'
LANGUAGE 'c';
and fun.c:
#include <postgresql/postgres.h>
#include <postgresql/utils/elog.h>
#include <postgresql/libpq/libpq-fs.h>
text *hupper (text *a) { int hossz,i;
hossz=a->vl_len; for (i=0;i<hossz;i++) { char ch; ch=a->vl_dat[i]; if ((ch>=97)&(ch<=122))
ch=ch-32; else if (ch=='á') ch='Á'; else if (ch=='é') ch='É'; else if (ch=='í') ch='Í'; else if
(ch=='ó')ch='Ó'; else if (ch=='ő') ch='Ő'; else if (ch=='ö') ch='Ö'; else if (ch=='ú') ch='Ú';
elseif (ch=='ű') ch='Ű'; else if (ch=='ü') ch='Ü'; a->vl_dat[i]=ch; }
return a;
}
We use this to make hungarian upper (=Hupper).
And two select:
gergo=> select mire from mamapenz;mire
-------betetebedebedebedebedebed
(6 rows)
gergo=> select hupper(mire) from mamapenz;hupper
--------BETETEBEDEBEDEBEDEBEDEBED
(6 rows)
this is good, and now:
gergo=> select mire from mamapenz; ^^^^^^^^^^^^^^^^^^^^^mire
-------BETETEBEDEBEDEBEDEBEDEBED
(6 rows)
After once hupper run on the table it will be upper case even I don't use hupper.
It can be fixed with a postgres restart or with 10-20 minutes of waiting.
If this is documented, sorry (but please point out where).
Thanks,
RISKO Gergely