Dashed if I can work this out. Help needed copying substring to another field

From: Robert Chalmers <robert(at)chalmers(dot)com(dot)au>
To: psql-general <pgsql-general(at)postgreSQL(dot)org>, sql(at)chalmers(dot)com(dot)au
Subject: Dashed if I can work this out. Help needed copying substring to another field
Date: 1999-01-30 07:03:42
Message-ID: 36B2AECE.B22BDFAD@chalmers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I'm really foxed on this. In a PostgreSQL database table,

I have three fields. "category","language","code"

"code" is made up of category+language+code-numbers
for example: 10CE4578P
or
9E457CT

So in this case, 10 is the 'category', CE is the 'language', and the rest makes
up the code.
or
So in the 2nd case, 9 is the 'category', E is the 'language', and the rest
makes up the code.

I have 2758 records with the third field, 'code' filled in already. Thats how
it comes. I want to extract the two first parts, and put them into their
respective fields. That is, take the '10' and put it into the 'category' field,
take the CE and put it into the 'language' field, and leave the 'code' field as
it is.

It looks like some sort of repetative statement needs to be written so it steps
down the entire table, adjusting each record as it goes, but I'm at a loss as
how to do it.

If I could discover a way to simply extract this info from the 'code' field on
the fly, with accuracy, I could probably forget the two fields of
category,language and simpy search on the code field, but I can't work it out.
Maybe I need to take a break...

Does anyone have any ideas? I could really use some help on this one...

Thanks
Robert

--
http://www.chalmers.com.au. Publications From China in 24 different languages.
English, French, German, Russian, Arabic, Spanish, Chinese, Burmese, Bengali,
Hindi, Indonesian, Italian, Japanese, Korean, Portuguese, Persian, Swahili,
Sinhalese, Thai, Tamil, Urdu, Vietnamese. China Books for CIBTC, Beijing.

Browse pgsql-general by date

  From Date Subject
Next Message Pawel Pierscionek 1999-01-30 10:14:00 unable to cerate uniqie index on macaddr !
Previous Message Charles Hornberger 1999-01-30 02:00:11 Re: [GENERAL] nested loops in joins, ambiguous rewrite rules