Skip to main content

Posts

Showing posts with the label PostgreSQL

Books

Tonight I was home alone with my kid. Fortunately for us (the kid and me) our PC is connected to the TV set. So, he watched his favorites DVDs, while I had Google Reader in play mode with slide show enabled and side by side windows. After playing the DVDs a dozen times, Google Reader showed this e-book post . PostgreSQL is my database of choice, so this book will be very appreciated. The PostgreSQL e-book is at: http://www.commandprompt.com/ppbook/

Regex within PostgreSQL

Regex (Regular expressions) are very useful. I had to make a SQL query to return only the firstname from a table where the field provides the full name. ideia_onde=# SELECT name FROM users; name -------------------------------- Linus Torvalds Randal Schwartz Steve Wozniak (3 rows) ideia_onde=# Now, with a simple substring using a regular expression: SELECT SUBSTRING(name, '(.*?(\\s))') FROM users; substring ----------- Linus Randal Steve (3 rows) ideia_onde=# What do I did? The substring function extracts from the name field everything (.*) until (?) a space character (\\s).