column_1 (varchar) has values with the format like 1024 MB, 2048 MB etc. There also exits
column_2 (int). Now I would like to parse the value in
column_1 and update the
column_2 with values like 1024, 2048. I am using PostgreSQL.
How do I do this ? I am fairly new to databases. Any help/suggestion is appreciated.
If your data is consistent, so that after a number it always contains a space and then something else, then the following expression will get you the number part:
This will split up your string along the spaces with the remaining chunks are indexed from 1 up to the last one, then the first one is picked. There are, of course, other possibilities around, for example using a regex, which probably other will add later :)
Now you can construct your
Notice that there is no
You find an example on SQLFiddle.