SQL LIKE condition to check for integer?

后端 未结 8 774
温柔的废话
温柔的废话 2020-12-01 01:11

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts wit

相关标签:
8条回答
  • 2020-12-01 01:55

    In PostreSQL you can use SIMILAR TO operator (more):

    -- only digits
    select * from books where title similar to '^[0-9]*$';
    -- start with digit
    select * from books where title similar to '^[0-9]%$';
    
    0 讨论(0)
  • 2020-12-01 01:57

    PostgreSQL supports regular expressions matching.

    So, your example would look like

    SELECT * FROM books WHERE title ~ '^\d+ ?' 
    

    This will match a title starting with one or more digits and an optional space

    0 讨论(0)
提交回复
热议问题