如何检查数组中是否包含字符串?

时间:2020-02-26 17:46:56

标签: sql postgresql

在我的 PostgreSQL 数据库(version: 11.4中,有一个名为table_1的表,该表只有一列。此列的数据类型是字符串数组(_varchar)。

| dependencies   |
|----------------|
|{\1}            | 
|{\1,\1\2}       |
|{\1,\1\2,\1\2\3}|

此外,我有一个名为table_2的表,其结构如下:

| employee       | dependence |
|----------------|------------|
| Alex           | \1         |
| Mark           | \1         |
| Lily           | \1\2       |
| Grace          | \1\2       |
| Evie           | \1\2       |
| Bob            | \1\2\3     |
| Mark           | \1\2       |

如何检查数组中是否包含字符串?就我而言,我试图检查dependence的{​​{1}}列值是否存在于table_2的{​​{1}}列的数组中。

换句话说,我正在尝试获得这样的结果:

dependencies
我尝试的

SQL请求:

table_1

1 个答案:

答案 0 :(得分:1)

尝试使用字段Sub ChangeFont() Dim bpFontName As String bpFontName = InputBox("What font would you like to change EVERYTHING to?") With ActivePresentation For Each Slide In .Slides For Each Shape In Slide.Shapes With Shape If .HasTextFrame Then If .TextFrame.HasText Then .TextFrame.TextRange.Font.Name = bpFontName 'Set font size below .TextFrame.TextRange.Font.Size = 30 'Set if you want the font bold below - msoFalse = no .TextFrame.TextRange.Font.Bold = msoTrue 'Set if you want the font bold below - msoFalse = no .TextFrame.TextRange.Font.Italic = msoTrue End If End If End With Next Next End With End Sub

TEXT[]

表_1

select dependencies ,count(*) from table_1 join table_2
on dependence  = ANY( dependencies)
group by 1

表_2

create table table_1
(
    dependencies text[]
);
insert into public.table_1 (dependencies) values ('{1}');
insert into public.table_1 (dependencies) values ('{1,12}');
insert into public.table_1 (dependencies) values ('{1,12,123}');