[SQL] Like with special character

2006-05-01 Thread tnodev

Hello,

I'm using postGre with tables which contain French character (éèçàù...). 
Is there a fonction which performs a like in replacing é (e cute) by e ?


thanks...

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [SQL] Like with special character

2006-05-01 Thread Guillaume LELARGE
Hi,

tnodev a écrit :
> I'm using postGre with tables which contain French character (éèçàù...).
> Is there a fonction which performs a like in replacing é (e cute) by e ?
> 

select translate('forêt', 'àâäéèêëîïôöùûü', 'aaaiioouuu');

Change the first word (forêt) by the string you want characters to be
replaced.

For more, see :
  http://docs.postgresqlfr.org/pgsql-8.1.3-fr/functions-string.html
(french docs)
  http://www.postgresql.org/docs/8.1/interactive/functions-string.html
(english docs)

BTW, it is PostgreSQL, not postGre.

Regards,


-- 
Guillaume.

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [SQL] join on a like

2006-05-01 Thread [EMAIL PROTECTED]
If you use a btree index on the column, you should be able to use it in
the like:
http://www.postgresql.org/docs/8.1/interactive/indexes-types.html.


---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [SQL] Like with special character

2006-05-01 Thread Oleg Bartunov

On Mon, 1 May 2006, tnodev wrote:


Hello,

I'm using postGre with tables which contain French character (?...). Is 
there a fonction which performs a like in replacing ? (e cute) by e ?


to_ascii() should helps you



thanks...

---(end of broadcast)---
TIP 6: explain analyze is your friend



Regards,
Oleg
_
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
Sternberg Astronomical Institute, Moscow University, Russia
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [SQL] Like with special character

2006-05-01 Thread TNO
Perfect, thanks

I found regex for postgreSql too, it's interesting too

select * from divers
where s_libelle ~* '^t(e|é|ê)'



Oleg Bartunov a écrit :
> On Mon, 1 May 2006, tnodev wrote:
>
>> Hello,
>>
>> I'm using postGre with tables which contain French character
>> (?...). Is there a fonction which performs a like in replacing ?
>> (e cute) by e ?
>
> to_ascii() should helps you
>
>>
>> thanks...
>>
>> ---(end of broadcast)---
>> TIP 6: explain analyze is your friend
>>
>
> Regards,
> Oleg
> _
> Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
> Sternberg Astronomical Institute, Moscow University, Russia
> Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
> phone: +007(495)939-16-83, +007(495)939-23-83
>
> ---(end of broadcast)---
> TIP 2: Don't 'kill -9' the postmaster
>
>
>

-- 
Il n'y a pas de mauvais langage, il n'y a que des bons programmeurs



---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] LinkedList

2006-05-01 Thread Guy Fraser
On Sat, 2006-29-04 at 01:50 -0500, Ben K. wrote:
> On Fri, 28 Apr 2006, Guy Fraser wrote:
> 
> >> -- HEAD
> >> insert into linkedlist values(null,1,0);
> >> insert into linkedlist values(1,2,10);
> >> insert into linkedlist values(2,3,20);
> >> insert into linkedlist values(3,4,30);
> >> insert into linkedlist values(4,5,40);
> >> -- TAIL
> >> insert into linkedlist values(5,null,50);
> 
> 
> 
> > Bad example of a double linked list, you also need an id for
> > the current node and the values of prevnode and nextnode do not
> > need to be ordered or contiguous as the example shows.
> 
> 
> 
> Wow. Interesting... I am willing to be corrected, but to me the "node" 
> field seems redundant, since it does not add any information. (Since each 
> item in the list is already uniquely identifiable without the "node".) 
> Certainly so, for traversing, which was the OP's intention.
> 
> It may save some steps in case of other operations but at the expense of 
> one more field. Please see below.
> 

The problem is that your way, there is no indicated way to determine
which node is which. For instance is you update any of your nodes 
then the node list would be out of order and your list would not 
work.

After I posted the message I realized there is another way to 
do this without adding an extra field, and it would be a closer 
example to how it is done in C. If you assigned the OID of the 
previous and next nodes rather than arbitrary integer, you could 
access each node independent of the order they are listed.

I have not messed around much with OIDs. I am not sure if 
OIDs change if an entry is updated.

In C you would use a pointer to storage location of previous 
and next "node" which is similar to using the OID. In some 
cases it can be necessary to use pointers to pointers when 
accessing variable length relocatable data, but that goes way 
past what this thread is about.

The example I provided, is still feasible and alleviates all 
unknowns at the expense of 4 bytes of storage for one integer
used as a fixed address for each node.

> 
> 
> > create table linkedlist(node int,prevnode int, nextnode int, val int);
> > insert into linkedlist values(1,null,2,0);
> > insert into linkedlist values(2,1,3,10);
> > insert into linkedlist values(3,2,4,30);
> > insert into linkedlist values(4,3,5,20);
> > insert into linkedlist values(5,4,6,40);
> > insert into linkedlist values(6,5,null,50);
> 
> > If we now wanted to reorder an item in the set you need
> > make some updates in a block, which I have not done before
> > but should be something like this:
> >
> > Move node 4 between 2 and 3 so that the values from head
> > to tail are ordered.
> >
> > update linkedlist set prevnode = '2',nextnode = '3' where node = '4';
> > update linkedlist set nextnode = '4' where node = '2';
> > update linkedlist set prevnode = '4' where node = '3';
> 
> 
> 
> If the intention is to change it from 0-10-30-20-40-50 to 
> 0-10-20-30-40-50, it would have been (in my design) exchanging node 3 and 
> node 4 below.
> 
>   null,1,0
>   1,2,10  <-- node 2
>   2,3,30  <-- node 3
>   3,4,20  <-- node 4
>   4,5,40
>   5,null,50
> 
> Now, it can be done by:
> 
> begin;
> update linkedlist set prevnode=2 where prevnode=3; -- node 4 = (2,4,20)
> update linkedlist set prevnode=3 where nextnode=3; -- node 3 = (3,3,30)
> update linkedlist set nextnode=3 where prevnode=2; -- node 4 = (2,3,20)
> update linkedlist set nextnode=4 where nextnode=3; -- node 3 = (3,4,30)
> commit;
> 
> achieving the same.
>   ...
>   2,3,20  <-- node 4, originally
>   3,4,30  <-- node 3, originally
>   ...
> 
> "node" will be more cost efficient if we insert an item at the beginning 
> of a long list, for example insert
>   (2,3,100)
> before node 3 (2,3,20), but at least the sql is simple;
> 
>   update linkedlist set prevnode = prevnode + 1 where prevnode > 1;
>   update linkedlist set nextnode = nextnode + 1 where nextnode > 2;
>   and then do insert (2,3,xxx)
> 
> This method can also be used for reordering.
> 
> The usefulness of the "node" will depend on the economics of these update 
> operations over keeping one more field.
> 
> But I think this is more of an exercise, and functions would be the proper 
> way for complex operations.
> 

As long as it works in real world use. Without some way of addressing 
each node, the idea of a linked list seems wrong, since a linked is 
supposed to hold the address of the previous and or next item in the 
list, assuming the data is always going to be correctly sorted so that
you can locate the next item by tupple number seems overly assumptive.
If it works for you great, your example may then be useful as a short
cut, but I don't believe in leaving things to chance when programming.




---(end of broadcast)---
TIP 6: explain analyze is your friend


[SQL] Counting the rows INSERTed/UPDATEd?

2006-05-01 Thread Mario Splivalo
I have found, I thinl, in the pg manual, the way to get the number of
rows inserted/updated, from within the plpgsql. I can't find it anymore,
is that still there, or I misread something earlier?

Mario
-- 
Mario Splivalo
Mob-Art
[EMAIL PROTECTED]

"I can do it quick, I can do it cheap, I can do it well. Pick any two."



---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [SQL] Counting the rows INSERTed/UPDATEd?

2006-05-01 Thread A. Kretschmer
am  01.05.2006, um 18:07:17 +0200 mailte Mario Splivalo folgendes:
> I have found, I thinl, in the pg manual, the way to get the number of
> rows inserted/updated, from within the plpgsql. I can't find it anymore,

http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS

GET DIAGNOSTICS integer_var = ROW_COUNT;


HTH, Andreas
-- 
Andreas Kretschmer(Kontakt: siehe Header)
Heynitz:  035242/47215,  D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===Schollglas Unternehmensgruppe=== 

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [SQL] Counting the rows INSERTed/UPDATEd?

2006-05-01 Thread Milen A. Radev
Mario Splivalo написа:
> I have found, I thinl, in the pg manual, the way to get the number of
> rows inserted/updated, from within the plpgsql. I can't find it anymore,
> is that still there, or I misread something earlier?
> 
>   Mario

May be this one?
http://www.postgresql.org/docs/8.1/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS


-- 
Milen A. Radev


---(end of broadcast)---
TIP 6: explain analyze is your friend