Postgres:正则表达式和嵌套查询,例如Unix管道 [英] Postgres: regex and nested queries something like Unix pipes
问题描述
命令应该执行:如果模式 *@he.com位于除标题之外的行上,则给出1作为输出:
user_id |用户名|电邮| passhash_md5 |登录| has_been_sent_a_moderator_message | was_last_checked_by_moderator_at_time | a_moderator
--------- + ---------- + ----------- + ------------ ---------------------- + ----------- + --------------- -------------------- + ----------------------------- ---------- + -------------
9 |他| he@he.com | 6f96cfdfe5ccc627cadf24b41725caa4 | 0 | 1 | 2009-08-23 19:16:46.316272 |简而言之,我想用Regex连接许多SELECT命令,就像Unix管道一样。上面的输出来自SELECT命令。一条与模式匹配的新SELECT命令应该给我1。
解决方案您的意思是
SELECT regexp_matches((在用户名='masi'的情况下从用户中选择任意名称),'masi');
您显然无法将记录( *
)喂给 regexp_matches
,但是我认为这不是您的问题,因为您提到了在主题中嵌套SQL查询的问题。
也许您的意思是
SELECT regexp_matches(wn,'masi')FROM(SELECT whatname AS wn FROM users WHERE username LIKE'%masi%')AS sq;
子查询产生多个结果。
Command should do: Give 1 as output if the pattern "*@he.com" is on the row excluding the headings:
user_id | username | email | passhash_md5 | logged_in | has_been_sent_a_moderator_message | was_last_checked_by_moderator_at_time | a_moderator
---------+----------+-----------+----------------------------------+-----------+-----------------------------------+---------------------------------------+-------------
9 | he | he@he.com | 6f96cfdfe5ccc627cadf24b41725caa4 | 0 | 1 | 2009-08-23 19:16:46.316272 |
In short, I want to connect many SELECT-commands with Regex, rather like Unix pipes. The output above is from a SELECT-command. A new SELECT-command with matching the pattern should give me 1.
解决方案 Did you mean
SELECT regexp_matches( (SELECT whatevername FROM users WHERE username='masi'), 'masi');
you obviously can not feed the record (*
) to regexp_matches
, but I assume this is not what your problem is, since you mention the issue of nesting SQL queries in the subject.
Maybe you meant something like
SELECT regexp_matches( wn, 'masi' ) FROM (SELECT whatevername AS wn FROM users WHERE username LIKE '%masi%') AS sq;
for the case when your subquery yields multiple results.
这篇关于Postgres:正则表达式和嵌套查询,例如Unix管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!