我将 s3 存储桶的文件路径存储在我的数据库中。文件可以是图片(jpg)或pdf。
假设我已经通过应用程序将photo.jpg上传到我的数据库,路径如下:
/{s3bucket}/filesuser/client/27801123/attachment/4510/file/1113/small/photo.jpg
/{s3bucket}/filesuser/client/27801124/attachment/4511/main/111/small/photo.jpg
/{s3bucket}/filesuser/client/27801124/attachment/4511/main/111/main
/{s3bucket}/filesuser/client/27801125/attachment/4512/file
/{s3bucket}/filesuser/client/27801126/attachment/4513/main
对于每个文件,我有 2 个根路径:
/{s3bucket}/filesuser/client/27801125/attachment/4512/file
/{s3bucket}/filesuser/client/27801126/attachment/4513/main
/{s3bucket}/filesuser/client/27801124/attachment/4511/main/111/main
我只需要通过where clause
root ='main'来获取。
例子:
select REGEXP_REPLACE(path_name, '.*/', '') as col2 from seg_table limit 10;
查询有效,我得到file, main, photo.jpg
了结果。
如何将其包含regexp
在 there 子句中?
例子:
WHERE (select REGEXP_REPLACE(path_name, '.*/', '') as col2
from seg_table) = 'main'
http://sqlfiddle.com/#!15/6d65d
有一个例子。请注意,col2
回报不仅是“主要”。我需要它只返回 main 并且我需要将它放在 where 子句中。我不能使用~
运算符,因为我需要执行以下操作:
FROM test1 t1
JOIN another_view AS s
WHERE s.full_path = substr(t1.full_path, char_pos '/file..' to get /filesuser/client/.../attachment/.../) || 'main'
不能使用'/main$';
,因为它会给我:
/{s3bucket}/filesuser/client/27801124/attachment/4511/main/111/main
代替
/{s3bucket}/filesuser/client/27801124/attachment/4511/main
~
POSIX 正则表达式运算符执行此操作的简单方法是使用
~
运算符。你总是可以更具体地使用你的正则表达式..