Last active
March 15, 2016 20:54
-
-
Save mhkeller/c9084cbe1febefb92de1 to your computer and use it in GitHub Desktop.
Find replace in Postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name | code | |
---|---|---|
Alabama | 01 | |
Alaska | 02 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this formula in column C2 and drag down to prepend the letter `a` in front of the contents of column B2 | |
// Excel requires double quotes | |
=CONCATENATE("a", B2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Docs http://www.postgresql.org/docs/current/static/functions-string.html | |
-- Postgresql requires single quotes. | |
-- Generic template | |
UPDATE your-table-name SET your-column-name = REPLACE(your-column-name, 'string-to-replace', 'what-to-replace-it-with'); | |
-- Example. Your table is called `my_table`, column is called `fips` and you've prepended an `a` before each value to maintain its identity as a string and now you want to remove it | |
UPDATE my_table SET fips = REPLACE(fips, 'a', ''); | |
-- Better example. Add a new column called `clean_fips` so you can compare the results against the old. You can create a new column via the CartoDB interface. | |
UPDATE my_table SET clean_fips = REPLACE(fips, 'a', ''); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment