postgresql - removing leading zero and hyphen in Postgres -


i need remove leading zeros , hyphens column value in postgresql database, example:

121-323-025-000 should 12132325 060579-0001 => 605791 482-322-004 => 4823224

timely appreciated.

postgresql string functions. more advanced string editing, regular expressions can powerful. aware complex regular expressions may not considered maintainable people not familiar them.

create table testdata (id text, expected text); insert testdata (id, expected) values     ('121-323-025-000', '12132325'),     ('060579-0001', '605791'),     ('482-322-004', '4823224'); select id, expected, regexp_replace(id, '(^|-)0*', '', 'g') computed   testdata; 

how regexp_replace works. in case beginning of string or hyphen place start matching. include zeros follow part of match. next replace match empty string. finally, global flag tells repeat search until reach end of string.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -