Thread: Substitute a Character
Hello everybody!! I have a field type text with folios like this: A98526 but I want to change de A for a 0 like this: 098526, exists a way to do this in a query??? Thanks in advanced!!!
Judith <jaltamirano@correolux.com.mx> schrieb: > Hello everybody!! I have a field type text with folios like this: > A98526 > > but I want to change de A for a 0 like this: 098526, exists a way to do > this in a query??? Perhaps something like this: test=# select regexp_replace('A98526', '^.', '0');regexp_replace ----------------098526 (1 row) http://www.postgresql.org/docs/8.1/interactive/functions-matching.html#FUNCTIONS-POSIX-REGEXP Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknow) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
> Hello everybody!! > > I have a field type text with folios like this: A98526 > > but I want to change de A for a 0 like this: 098526, exists a way to > do this in a query??? > > Thanks in advanced!!! You should look at these functions: http://www.postgresql.org/docs/8.1/static/functions-string.html This for example might work for you: select translate('A98526', 'A', '0'); Bye, Chris. -- Chris Mair http://www.1006.org
On 9/6/06 12:53 PM, "Judith" <jaltamirano@correolux.com.mx> wrote: > Hello everybody!! > > I have a field type text with folios like this: A98526 > > but I want to change de A for a 0 like this: 098526, exists a way to > do this in a query??? select translate( 'A98526', 'A', '0' ); translate ------------ 098526 1 record(s) selected [Fetch MetaData: 1/ms] [Fetch Data: 0/ms] [Executed: 9/6/06 4:18:44 PM EDT ] [Execution: 99/ms] > > Thanks in advanced!!! > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend -- Daryl Email *my = [ daryl at: @"eddl" dot: @"us" ]; Weblog *blog = @²http://itsallsemantics.com²;
Hi, Try: UPDATE foe SET field = regexp_replace(field, '^.', '0'); OR UPDATE foe SET field = regexp_replace(field, 'A', '0'); This will replace in table "foe" in the column "field" 'A' with '0'; Regards, Kaloyan Iliev Judith wrote: > Hello everybody!! I have a field type text with folios like > this: A98526 > > but I want to change de A for a 0 like this: 098526, exists a way > to do this in a query??? > > Thanks in advanced!!! > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > >