PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Regular Expression to Update a field
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Regular Expression to Update a field

Réponse
 
LinkBack Outils de la discussion
Vieux 26/09/2007, 11h08   #1
mcl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Regular Expression to Update a field

I am very new to MySQL and programming and I have some errors in a
field in my database

Field = 'Brian, Bill,Joe, Peter'

Some fields are missing the space after the 'comma'

I need to match on any 'comma + character'
but not 'comma + space'
and replace with 'comma + space + original character'

There can be more than one error in a field

so I guess I need something like

Update mytable set myfield = replace (mytable.myfield, some wonderful
regexp)

Any gratefully appreciated

Richard

  Réponse avec citation
Vieux 26/09/2007, 11h19   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular Expression to Update a field

On 26 Sep, 11:08, mcl <mcl.off...@googlemail.com> wrote:
> I am very new to MySQL and programming and I have some errors in a
> field in my database
>
> Field = 'Brian, Bill,Joe, Peter'
>
> Some fields are missing the space after the 'comma'
>
> I need to match on any 'comma + character'
> but not 'comma + space'
> and replace with 'comma + space + original character'
>
> There can be more than one error in a field
>
> so I guess I need something like
>
> Update mytable set myfield = replace (mytable.myfield, some wonderful
> regexp)
>
> Any gratefully appreciated
>
> Richard


Your problem is that the field violates First Normal Form (1NF).

Normalise your database and this problem will never ooccur.
http://del.icio.us/Captain_Paralytic/normalization

  Réponse avec citation
Vieux 26/09/2007, 11h47   #3
mcl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular Expression to Update a field

On 26 Sep, 11:19, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 26 Sep, 11:08, mcl <mcl.off...@googlemail.com> wrote:
>
>
>
> > I am very new to MySQL and programming and I have some errors in a
> > field in my database

>
> > Field = 'Brian, Bill,Joe, Peter'

>
> > Some fields are missing the space after the 'comma'

>
> > I need to match on any 'comma + character'
> > but not 'comma + space'
> > and replace with 'comma + space + original character'

>
> > There can be more than one error in a field

>
> > so I guess I need something like

>
> > Update mytable set myfield = replace (mytable.myfield, some wonderful
> > regexp)

>
> > Any gratefully appreciated

>
> > Richard

>
> Your problem is that the field violates First Normal Form (1NF).
>
> Normalise your database and this problem will never ooccur.http://del.icio.us/Captain_Paralytic/normalization


Captain,

Thanks for the reply, but I do not know what you mean.

It is a Text field and I want to put a space after every comma where
there is not one for presentation purposes.

Richard

  Réponse avec citation
Vieux 26/09/2007, 12h11   #4
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular Expression to Update a field

On 26 Sep, 11:47, mcl <mcl.off...@googlemail.com> wrote:
> On 26 Sep, 11:19, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 26 Sep, 11:08, mcl <mcl.off...@googlemail.com> wrote:

>
> > > I am very new to MySQL and programming and I have some errors in a
> > > field in my database

>
> > > Field = 'Brian, Bill,Joe, Peter'

>
> > > Some fields are missing the space after the 'comma'

>
> > > I need to match on any 'comma + character'
> > > but not 'comma + space'
> > > and replace with 'comma + space + original character'

>
> > > There can be more than one error in a field

>
> > > so I guess I need something like

>
> > > Update mytable set myfield = replace (mytable.myfield, some wonderful
> > > regexp)

>
> > > Any gratefully appreciated

>
> > > Richard

>
> > Your problem is that the field violates First Normal Form (1NF).

>
> > Normalise your database and this problem will never ooccur.http://del.icio.us/Captain_Paralytic/normalization

>
> Captain,
>
> Thanks for the reply, but I do not know what you mean.
>
> It is a Text field and I want to put a space after every comma where
> there is not one for presentation purposes.
>
> Richard- Hide quoted text -
>
> - Show quoted text -


It looks as though your field contains multiple values (a list of
names). Is this not the case?

"The first normal form (or 1NF) requires that the values in each
column of a table are atomic. By atomic we mean that there are no sets
of values within a column."

  Réponse avec citation
Vieux 26/09/2007, 15h35   #5
mcl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular Expression to Update a field

On 26 Sep, 12:11, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 26 Sep, 11:47, mcl <mcl.off...@googlemail.com> wrote:
>
>
>
> > On 26 Sep, 11:19, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > On 26 Sep, 11:08, mcl <mcl.off...@googlemail.com> wrote:

>
> > > > I am very new to MySQL and programming and I have some errors in a
> > > > field in my database

>
> > > > Field = 'Brian, Bill,Joe, Peter'

>
> > > > Some fields are missing the space after the 'comma'

>
> > > > I need to match on any 'comma + character'
> > > > but not 'comma + space'
> > > > and replace with 'comma + space + original character'

>
> > > > There can be more than one error in a field

>
> > > > so I guess I need something like

>
> > > > Update mytable set myfield = replace (mytable.myfield, some wonderful
> > > > regexp)

>
> > > > Any gratefully appreciated

>
> > > > Richard

>
> > > Your problem is that the field violates First Normal Form (1NF).

>
> > > Normalise your database and this problem will never ooccur.http://del.icio.us/Captain_Paralytic/normalization

>
> > Captain,

>
> > Thanks for the reply, but I do not know what you mean.

>
> > It is a Text field and I want to put a space after every comma where
> > there is not one for presentation purposes.

>
> > Richard- Hide quoted text -

>
> > - Show quoted text -

>
> It looks as though your field contains multiple values (a list of
> names). Is this not the case?
>
> "The first normal form (or 1NF) requires that the values in each
> column of a table are atomic. By atomic we mean that there are no sets
> of values within a column."


Captain,

No - it is not the case. I just used names as an example, to show my
problem / question. It is a text field, which has been created from
various sources and the spacing was in error in one or two cases and I
thought a regular expression would be the best way of fixing it as I
had some matches and some 'not' matches in the same field / test.

I can not find an example of 'sql' where a regular expression is used
to update a field in the circumstances I have outlined.

If someone can point me to an example - I would be most grateful.

Richard

  Réponse avec citation
Vieux 26/09/2007, 15h48   #6
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular Expression to Update a field

On 26 Sep, 15:35, mcl <mcl.off...@googlemail.com> wrote:
> On 26 Sep, 12:11, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 26 Sep, 11:47, mcl <mcl.off...@googlemail.com> wrote:

>
> > > On 26 Sep, 11:19, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > > On 26 Sep, 11:08, mcl <mcl.off...@googlemail.com> wrote:

>
> > > > > I am very new to MySQL and programming and I have some errors in a
> > > > > field in my database

>
> > > > > Field = 'Brian, Bill,Joe, Peter'

>
> > > > > Some fields are missing the space after the 'comma'

>
> > > > > I need to match on any 'comma + character'
> > > > > but not 'comma + space'
> > > > > and replace with 'comma + space + original character'

>
> > > > > There can be more than one error in a field

>
> > > > > so I guess I need something like

>
> > > > > Update mytable set myfield = replace (mytable.myfield, some wonderful
> > > > > regexp)

>
> > > > > Any gratefully appreciated

>
> > > > > Richard

>
> > > > Your problem is that the field violates First Normal Form (1NF).

>
> > > > Normalise your database and this problem will never ooccur.http://del.icio.us/Captain_Paralytic/normalization

>
> > > Captain,

>
> > > Thanks for the reply, but I do not know what you mean.

>
> > > It is a Text field and I want to put a space after every comma where
> > > there is not one for presentation purposes.

>
> > > Richard- Hide quoted text -

>
> > > - Show quoted text -

>
> > It looks as though your field contains multiple values (a list of
> > names). Is this not the case?

>
> > "The first normal form (or 1NF) requires that the values in each
> > column of a table are atomic. By atomic we mean that there are no sets
> > of values within a column."

>
> Captain,
>
> No - it is not the case. I just used names as an example, to show my
> problem / question. It is a text field, which has been created from
> various sources and the spacing was in error in one or two cases and I
> thought a regular expression would be the best way of fixing it as I
> had some matches and some 'not' matches in the same field / test.
>
> I can not find an example of 'sql' where a regular expression is used
> to update a field in the circumstances I have outlined.
>
> If someone can point me to an example - I would be most grateful.
>
> Richard- Hide quoted text -
>
> - Show quoted text -


Ok, now we know what teh actual situation is...
REGEXs in MySQL are used for pattern matching, not data manipulation.

You could try:
REPLACE(REPLACE(field,', ',','),',',', ')

  Réponse avec citation
Vieux 26/09/2007, 16h17   #7
mcl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular Expression to Update a field

On 26 Sep, 15:48, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 26 Sep, 15:35, mcl <mcl.off...@googlemail.com> wrote:
>
>
>
> > On 26 Sep, 12:11, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > On 26 Sep, 11:47, mcl <mcl.off...@googlemail.com> wrote:

>
> > > > On 26 Sep, 11:19, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > > > On 26 Sep, 11:08, mcl <mcl.off...@googlemail.com> wrote:

>
> > > > > > I am very new to MySQL and programming and I have some errors in a
> > > > > > field in my database

>
> > > > > > Field = 'Brian, Bill,Joe, Peter'

>
> > > > > > Some fields are missing the space after the 'comma'

>
> > > > > > I need to match on any 'comma + character'
> > > > > > but not 'comma + space'
> > > > > > and replace with 'comma + space + original character'

>
> > > > > > There can be more than one error in a field

>
> > > > > > so I guess I need something like

>
> > > > > > Update mytable set myfield = replace (mytable.myfield, some wonderful
> > > > > > regexp)

>
> > > > > > Any gratefully appreciated

>
> > > > > > Richard

>
> > > > > Your problem is that the field violates First Normal Form (1NF).

>
> > > > > Normalise your database and this problem will never ooccur.http://del.icio.us/Captain_Paralytic/normalization

>
> > > > Captain,

>
> > > > Thanks for the reply, but I do not know what you mean.

>
> > > > It is a Text field and I want to put a space after every comma where
> > > > there is not one for presentation purposes.

>
> > > > Richard- Hide quoted text -

>
> > > > - Show quoted text -

>
> > > It looks as though your field contains multiple values (a list of
> > > names). Is this not the case?

>
> > > "The first normal form (or 1NF) requires that the values in each
> > > column of a table are atomic. By atomic we mean that there are no sets
> > > of values within a column."

>
> > Captain,

>
> > No - it is not the case. I just used names as an example, to show my
> > problem / question. It is a text field, which has been created from
> > various sources and the spacing was in error in one or two cases and I
> > thought a regular expression would be the best way of fixing it as I
> > had some matches and some 'not' matches in the same field / test.

>
> > I can not find an example of 'sql' where a regular expression is used
> > to update a field in the circumstances I have outlined.

>
> > If someone can point me to an example - I would be most grateful.

>
> > Richard- Hide quoted text -

>
> > - Show quoted text -

>
> Ok, now we know what teh actual situation is...
> REGEXs in MySQL are used for pattern matching, not data manipulation.
>
> You could try:
> REPLACE(REPLACE(field,', ',','),',',', ')


Captain,

Perfect - make them all comma and then replace with comma space. I
was not aware of nesting as you have shown. It worked.

REGEXP - more reading but noted for pattern matching only. I was
probably thinking about 'sed' a program I once used many moons ago.

Thanks again

Richard

  Réponse avec citation
Vieux 26/09/2007, 16h30   #8
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular Expression to Update a field

On 26 Sep, 16:17, mcl <mcl.off...@googlemail.com> wrote:
> On 26 Sep, 15:48, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 26 Sep, 15:35, mcl <mcl.off...@googlemail.com> wrote:

>
> > > On 26 Sep, 12:11, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > > On 26 Sep, 11:47, mcl <mcl.off...@googlemail.com> wrote:

>
> > > > > On 26 Sep, 11:19, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > > > > On 26 Sep, 11:08, mcl <mcl.off...@googlemail.com> wrote:

>
> > > > > > > I am very new to MySQL and programming and I have some errors in a
> > > > > > > field in my database

>
> > > > > > > Field = 'Brian, Bill,Joe, Peter'

>
> > > > > > > Some fields are missing the space after the 'comma'

>
> > > > > > > I need to match on any 'comma + character'
> > > > > > > but not 'comma + space'
> > > > > > > and replace with 'comma + space + original character'

>
> > > > > > > There can be more than one error in a field

>
> > > > > > > so I guess I need something like

>
> > > > > > > Update mytable set myfield = replace (mytable.myfield, some wonderful
> > > > > > > regexp)

>
> > > > > > > Any gratefully appreciated

>
> > > > > > > Richard

>
> > > > > > Your problem is that the field violates First Normal Form (1NF).

>
> > > > > > Normalise your database and this problem will never ooccur.http://del.icio.us/Captain_Paralytic/normalization

>
> > > > > Captain,

>
> > > > > Thanks for the reply, but I do not know what you mean.

>
> > > > > It is a Text field and I want to put a space after every comma where
> > > > > there is not one for presentation purposes.

>
> > > > > Richard- Hide quoted text -

>
> > > > > - Show quoted text -

>
> > > > It looks as though your field contains multiple values (a list of
> > > > names). Is this not the case?

>
> > > > "The first normal form (or 1NF) requires that the values in each
> > > > column of a table are atomic. By atomic we mean that there are no sets
> > > > of values within a column."

>
> > > Captain,

>
> > > No - it is not the case. I just used names as an example, to show my
> > > problem / question. It is a text field, which has been created from
> > > various sources and the spacing was in error in one or two cases and I
> > > thought a regular expression would be the best way of fixing it as I
> > > had some matches and some 'not' matches in the same field / test.

>
> > > I can not find an example of 'sql' where a regular expression is used
> > > to update a field in the circumstances I have outlined.

>
> > > If someone can point me to an example - I would be most grateful.

>
> > > Richard- Hide quoted text -

>
> > > - Show quoted text -

>
> > Ok, now we know what teh actual situation is...
> > REGEXs in MySQL are used for pattern matching, not data manipulation.

>
> > You could try:
> > REPLACE(REPLACE(field,', ',','),',',', ')

>
> Captain,
>
> Perfect - make them all comma and then replace with comma space. I
> was not aware of nesting as you have shown. It worked.
>
> REGEXP - more reading but noted for pattern matching only. I was
> probably thinking about 'sed' a program I once used many moons ago.
>
> Thanks again
>
> Richard- Hide quoted text -
>
> - Show quoted text -


In most languages functions can be nested.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h48.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,22537 seconds with 16 queries