需要从我的 PostgreSQL 表的 file_path 列中提取文件扩展名。请帮助我实现使用选择查询将不同的文件扩展名提取为列表。
有这样的桌子
id | 文件路径 |
---|---|
1 | https://example.com/uploads/profile_pic.jpeg |
2 | https://example.com/public/upload/resume.png |
预期输出如下
行号 | 扩展 |
---|---|
1 | jpeg |
2 | png |
我的询问
select reverse(substring(reverse(file_path) from 1 for strpos(reverse(file_path),'.')-1)) as extension from pgsql_table_files;
create table file_ext(id integer, file_path varchar);
insert into file_ext values (1, 'https://example.com/uploads/profile_pic.jpeg'), (2, 'https://example.com/public/upload/resume.png'), (3, 'https://example.com/public/upload/cover_letter.png'), (4, 'https://example.com/uploads/cat_pic.jpeg');
select distinct split_part(file_path , '.', -1) from file_ext;
split_part
------------
png
jpeg