postgresql - How to use substring of result in PosrgreSQL/SQL -


i don't know how name syntax properly. got table (say t) column a in store entries in format user-yyyy-mmdd. want extract rows a column's year part (yyyy part) greater 2010. e.g.

table t +----------------+ |              | +----------------+ | user-2011-1234*| | user-1992-1923 | | user-2014-1234*| +----------------+ 

(*) want: yyyy part greater 2010. sql should looks this, dont know how in postgresql.

 select * t a[5-8] > 2010 

thanks!

select * t to_number(substr(a, 6, 4)) > 2010; 

note fail error if string cannot converted number

more details in manual: http://www.postgresql.org/docs/current/static/functions-string.html

btw: storing more 1 information in single column bad design. should store username , date in 2 different columns. additionally storing dates varchar bad idea. date should stored date not varchar


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -