Postgres SELECT语句,其中字段值以

Ahm*_*med 2 postgresql select where-clause

我有一个名为postgres的数据库表:web_data

目前,我正在运行以下SQL select语句:

SELECT url_path FROM web_data WHERE url_path IS NOT NULL
Run Code Online (Sandbox Code Playgroud)

这是我将为url_path获得的一些示例结果:

/
/aboutus.html
/services.php
/images/twitter_counter.png
/images/facebook_counter.png
/mobile/windows/TileTemplate.xml
/en_US/fbevents.js
/css/style.css
Run Code Online (Sandbox Code Playgroud)

我想返回结果,其中url_path的最终值为以下之一:

/
.html
.htm
.php
.asp
.aspx
.pdf
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以将其放入SQL语句中,而不是获取所有结果,然后使用类似PHP的方法进行处理?

a_h*_*ame 5

使用LIKE运算符:

select url_path
from web_data
where url_path like '%.htm'
   or url_path like '%.html'
   or url_path like '%.php'
   or url_path like '%.asp'
   or url_path like '%.aspx'
   or url_path like '%.pdf'
   or url_path like '%/';
Run Code Online (Sandbox Code Playgroud)

http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-LIKE