字段值以结尾的 Postgres SELECT 语句
Postgres SELECT statement where field value ends with
我有一个名为 table 的 postgres 数据库:web_data
目前我运行以下SQLselect声明:
SELECT url_path FROM web_data WHERE url_path IS NOT NULL
以下是我将获得的一些示例结果 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
我想要 return 结果,其中 url_path 的最终值是以下之一:
/
.html
.htm
.php
.asp
.aspx
.pdf
有没有办法将其放入 SQL 语句中,而不是获取所有结果,然后使用 PHP 之类的东西进行检查?
使用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 '%/';
http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-LIKE
我有一个名为 table 的 postgres 数据库:web_data
目前我运行以下SQLselect声明:
SELECT url_path FROM web_data WHERE url_path IS NOT NULL
以下是我将获得的一些示例结果 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
我想要 return 结果,其中 url_path 的最终值是以下之一:
/
.html
.htm
.php
.asp
.aspx
.pdf
有没有办法将其放入 SQL 语句中,而不是获取所有结果,然后使用 PHP 之类的东西进行检查?
使用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 '%/';
http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-LIKE