Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 获取每个<;标签>;字符串中的stackexchange数据库_Sql_Postgresql_Set Returning Functions_Dataexplorer - Fatal编程技术网

Sql 获取每个<;标签>;字符串中的stackexchange数据库

Sql 获取每个<;标签>;字符串中的stackexchange数据库,sql,postgresql,set-returning-functions,dataexplorer,Sql,Postgresql,Set Returning Functions,Dataexplorer,我的问题的模拟代码: SELECT Id FROM Tags WHERE TagName IN '<osx><keyboard><security><screen-lock>' 如何创建标签的唯一列表,以在标签表中查找标签,而不是在此硬编码版本中查找标签: SELECT * FROM Tags WHERE TagName = 'osx' OR TagName = 'keyboard' OR TagName = 'sec

我的问题的模拟代码:

SELECT Id FROM Tags WHERE TagName IN '<osx><keyboard><security><screen-lock>'
如何创建标签的唯一列表,以在
标签
表中查找标签,而不是在此硬编码版本中查找标签:

SELECT * FROM Tags
  WHERE TagName = 'osx' 
     OR TagName = 'keyboard' 
     OR TagName = 'security'
这是一本书


Stackexchange使用T-SQL,我的本地副本使用Postgres应用程序在postgresql下运行。

我已将数据简化为仅相关列,并将其命名为
标记
,以演示示例

样本数据

create table posthistory(tags text);
insert into posthistory values
  ('<lion><backup><time-machine>'),
  ('<spotlight><alfred><photo-booth>'),
  ('<lion><pdf><preview>'),
  ('<pdf>'),
  ('<asd>');
创建表posthistory(标记文本);
插入到posthistory值中
(''),

(“以预览其工作原理。

假设此表定义:

CREATE TABLE posthistory(post_id int PRIMARY KEY, tags text);
具体取决于您想要什么:


若要将字符串转换为数组,请修剪前导和尾随“”,然后处理您的Postgres版本丢失。@ErwinBrandstetter我非常感谢任何独立于版本的解决方案。
WHERE TagName=###TagName:string?osx##
也不是有效的t-SQL。我猜数据资源管理器在数据资源管理器中进行了一些查询预处理s行提供一个字符串输入字段,默认值为“osx”。请参阅的查询参数部分。
SELECT DISTINCT
  unnest(
    regexp_split_to_array(
      trim('><' from tags), '><'
    )
  )
FROM
  posthistory
CREATE TABLE posthistory(post_id int PRIMARY KEY, tags text);
SELECT *, string_to_array(trim(tags, '><'), '><') AS tag_arr
FROM   posthistory;
SELECT DISTINCT tag
FROM   posthistory, unnest(string_to_array(trim(tags, '><'), '><')) tag;
SELECT DISTINCT tag
FROM   posthistory, regexp_split_to_table(trim(tags, '><'), '><') tag;
SELECT *
FROM   posthistory
WHERE  tags LIKE '%<security>%'
AND    tags LIKE '%<osx>%';
SELECT TOP 100
       PostId, UserId, Text AS Tags FROM PostHistory
WHERE  year(CreationDate) = 2011
AND    PostHistoryTypeId IN (3  -- initial tags
                           , 6  -- edit tags
                           , 9) -- rollback tags
AND    Text LIKE ('%<' + ##TagName:String?postgresql## + '>%');