Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-24 Thread Tom Lane
Greg Stark <[EMAIL PROTECTED]> writes: > The glibc docs sample code suggests using 2x the original string > length for the initial buffer. My testing showed that *always* > triggered the exceptional case. A bit of experimentation lead to the > 3x+4 which eliminates it except for 0 and 1 byte string

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-24 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > On Fri, 22 Aug 2003, Tom Lane wrote: >> I'd go so far as to make it a critical section --- that ensures that any >> ERROR will be turned to FATAL, even if it's in a subroutine you call. > I didn't know we could do that, could be handy, although the comme

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-23 Thread Joe Conway
Greg Stark wrote: Joe Conway <[EMAIL PROTECTED]> writes: if (sigsetjmp(Warn_restart, 1) != 0) { memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); newlocale = setlocale(LC_COLLATE, oldlocale); if (!newlocale) elog(PANIC, "setlocale failed to reset locale: %s", localestr);

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-23 Thread Greg Stark
Joe Conway <[EMAIL PROTECTED]> writes: > > if (sigsetjmp(Warn_restart, 1) != 0) > > { > > memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); > > newlocale = setlocale(LC_COLLATE, oldlocale); > > if (!newlocale) > > elog(PANIC, "setlocale failed to reset locale: %s",

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-23 Thread Joe Conway
Joe Conway wrote: What about something like this? Oops! Forgot to restrore error handling. See below: Joe 8< #include #include #include "postgres.h" #include "fmgr.h" #include "tcop/tcopprot.h" #include "utils/builtins.h" #define GET_STR(textp) \ DatumGetCStri

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-23 Thread Joe Conway
Greg Stark wrote: Yeah I thought of that. But if making it a critical section is cheap then it's probably a better approach. The problem with restoring the locale for the palloc is that if the user is unlucky he might sort a table of thousands of strings that all trigger the exception case. What ab

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-23 Thread Stephan Szabo
On 23 Aug 2003, Greg Stark wrote: > Stephan Szabo <[EMAIL PROTECTED]> writes: > > > Since most of that work is for an exceptional case, maybe it'd be safer > > (although slower) to structure the function as > > Yeah I thought of that. But if making it a critical section is cheap then it's > probab

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-23 Thread Greg Stark
Stephan Szabo <[EMAIL PROTECTED]> writes: > Since most of that work is for an exceptional case, maybe it'd be safer > (although slower) to structure the function as Yeah I thought of that. But if making it a critical section is cheap then it's probably a better approach. The problem with restorin

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-23 Thread Stephan Szabo
On Fri, 22 Aug 2003, Stephan Szabo wrote: > On Fri, 22 Aug 2003, Tom Lane wrote: > > > Stephan Szabo <[EMAIL PROTECTED]> writes: > > > On 22 Aug 2003, Greg Stark wrote: > > >> If it's deemed a reasonable approach and nobody has any fatal flaws then I > > >> expect it would be useful to put in the

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-22 Thread Stephan Szabo
On Fri, 22 Aug 2003, Tom Lane wrote: > Stephan Szabo <[EMAIL PROTECTED]> writes: > > On 22 Aug 2003, Greg Stark wrote: > >> If it's deemed a reasonable approach and nobody has any fatal flaws then I > >> expect it would be useful to put in the contrib directory? > > > I'm not sure that ERROR if th

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-22 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > On 22 Aug 2003, Greg Stark wrote: >> If it's deemed a reasonable approach and nobody has any fatal flaws then I >> expect it would be useful to put in the contrib directory? > I'm not sure that ERROR if the locale cannot be put back is sufficient > (alth

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-22 Thread Stephan Szabo
On 22 Aug 2003, Greg Stark wrote: > > So, I needed a way to sort using collation rules other than the one the > database was built with. So I wrote up the following function exposing strxfrm > with an extra parameter to specify the LC_COLLATE value to use. > > This is my first C function so I'm r

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-22 Thread Peter Eisentraut
Greg Stark writes: > This is my first C function so I'm really unsure that I've done the right > thing. For the most part I pattern-matched off the string_io code in the > contrib directory. That was just about the worst example you could have picked. Please forget everything you have seen and s

Re: [HACKERS] Collation rules and multi-lingual databases

2003-08-22 Thread Greg Stark
So, I needed a way to sort using collation rules other than the one the database was built with. So I wrote up the following function exposing strxfrm with an extra parameter to specify the LC_COLLATE value to use. This is my first C function so I'm really unsure that I've done the right thing. F