×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Change existing values

Change existing values

Change existing values

(OP)
I'm new to this but so far what I'm doing seems to be working okay.
I have some useful data that was entered into a "junk" table that I was using as I learned PostgreSQL.
Someone else entered some of the data and didn't realize that in the following entry:

CODE

Millstead - 2 In. x 6 In. x 12 Ft. Dimensional Yellow Pine Lumber

The following are not useful in this column. (Only Yellow Pine IS useful, but in another column)

CODE

Millstead - 2
and

CODE

Dimensional Yellow Pine Lumber


(These are not very many entries, but I want to learn from this now)

I can remove these through perl dbi.
I was wondering if these types of changes can made with pure SQL, or if it has to be done through something like perl?

I want

CODE

2 In. x 6 In. x 12 Ft.
as end result.

RE: Change existing values

Hi

Probably can be done without programming, just executing the SQL statements in psql.

But I not understand your rule, so I can not suggest how to write your update.

Feherke.
http://rootshell.be/~feherke/

RE: Change existing values

(OP)
What i am asking is:

I have an entry,  xyz
I want to know if I can remove x and z, but leave y in updated entry.

Can this process be done directly in just psql, or only through external programming?

I saw a lot of stuff in the advanced section of the manual that I didn't understand at first glance. Have vague idea what procedures and typecasts are, not a clue how arrays are used.

RE: Change existing values

(OP)
Okay, after looking at some other posts, found page on regex functions.
I am guessing that I need to use something like


 Some examples:

regexp_replace('foobarbaz', 'b..', 'X')
                                   fooXbaz
regexp_replace('foobarbaz', 'b..', 'X', 'g')
                                   fooXX
regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g')
                                   fooXarYXazY



Except replacing 'Millstead' with nothing?



 

RE: Change existing values

(OP)
OK, I've got it for making one change at a time.

CODE

vendor_prods=# update products set product_description = regexp_replace((select product_description from products where product_description like 'Millstead%' AND product_id=19
), 'Millstead - ', '') where product_id=19;

Works well, Is this the best way to write this?

Now where do I look to figure out how to automate this for a series of records? (this would now be very easy for me to automate with dbi, but I'd like to learn how to do through psql)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close