我正在使用 debian 压缩包,它说功能不存在?
postgresql pattern-matching postgresql-8.4 postgresql-extensions
假设我有一个words包含非常多记录的表。
列是id和name。
在words我的表格中,例如:
'systematic', '????','gear','synthesis','mysterious', etc.
Run Code Online (Sandbox Code Playgroud)
注意:我们也有 utf8 字样。
如何有效地查询,看看哪些词包含字母's','m'和'e'(所有的他们)?
输出将是:
systematic,mysterious
Run Code Online (Sandbox Code Playgroud)
我不知道如何做这样的事情。它应该是高效的,否则我们的服务器会受到影响。
我已经设置ft_min_word_len = 1为my.cnf文件,也SHOW VARIABLES LIKE 'ft_min_word%'显示ft_min_word_len as 1. 然后我重新加载了所有数据库表,它仍然没有搜索一个字符的单词。
我的表:
CREATE TABLE IF NOT EXISTS event (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(80) NOT NULL,
description TEXT,
time TIMESTAMP DEFAULT 0,
FULLTEXT(name)
);
Run Code Online (Sandbox Code Playgroud)
我的查询:
SELECT event.id AS eid,
event.name AS ename
FROM event
WHERE MATCH(event.name) AGAINST('+W*' IN BOOLEAN MODE)
Run Code Online (Sandbox Code Playgroud)
我正在寻找的事件名称是 W.W.W. + Pavel Fajt + Vladimir 518 @ Sono
请问还有什么可能导致问题?
编辑:我正在使用 InnoDB,抱歉我之前没有提到过。
我希望有人能用这个引导我朝着正确的方向前进。我有一张表,上面有学生成绩。
Create Table StudentGrades
(
StudentID references Student(StudentID) int not null,
GradeIssued varchar(1) not null,
WhenIssued datetime not null default(getdate())
)
Run Code Online (Sandbox Code Playgroud)
我想编写一个查询,执行以下操作:查找成绩(按顺序)为 D,然后是 C,然后是另一个 C,然后是 A 的学生。我知道方向(因为成绩的日期发布)模式应该在,但我想不出如何在不使用游标的情况下编写它。
根据我的查询经验,我通过 WHERE 和 HAVING 子句进行过滤,但是当我想找到特定模式时,我不确定该去哪里。
在 PostgreSQL 9.4 中,具有以下架构:
CREATE TABLE people (
id INTEGER PRIMARY KEY,
name TEXT,
junk CHAR(1000)
);
INSERT INTO people(id, name)
SELECT generate_series(1,100000), md5(random()::text);
CREATE INDEX ON people (name text_pattern_ops);
Run Code Online (Sandbox Code Playgroud)
如果我按名称搜索,则使用索引:
test=# explain analyze select id, name from people where name like 'a%';
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on people (cost=248.59..1160.92 rows=6061 width=37) (actual time=2.412..8.340 rows=6271 loops=1)
Filter: (name ~~ 'a%'::text)
Heap Blocks: exact=834
-> Bitmap Index Scan on people_name_idx (cost=0.00..247.08 rows=6266 width=0) (actual time=2.123..2.123 rows=6271 loops=1)
Index Cond: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试编写一个函数来检查一个字符串是否包含一个数字,而该数字不是更大数字的一部分(换句话说,如果要搜索的数字是 '6' 而字符串是 '7+16+2'它应该返回 false,因为这个字符串中的 '6' 是数字 '16' 的一部分)
我写了下面的函数(它很长,但我打算在重构之前先测试它)
在测试时,我发现了一个错误,它仅通过逻辑运行找到的数字的第一个实例。因此,使用 '6' 对 '16+7+9+6' 运行此函数将返回 false,因为它确定第一个 '6' 是更大数字的一部分并停止处理。
我认为要解决这个问题,我必须实现一个循环来缩短 'haystack' 字符串(这样,使用示例 '16+7+9+6',该函数在消除后继续检查 '+7+9+6'第一个“6”)但在花时间使已经复杂的函数变得更加复杂之前,我想检查是否有更简单的方法来实现相同的目标?
drop function dbo.runners_contain_runner
go
create function dbo.runners_contain_runner(@runner varchar(max), @runners varchar(max))
returns int
as
begin
/*
eliminate the plus sign from @runners so that the
'isnumeric' function doesn't return false positives (it returns 1 for '+')
*/
set @runners = replace(@runners,'+','_' )
declare @ret int;
set @ret = 0;
-- if the runner is the only runner return …Run Code Online (Sandbox Code Playgroud) 我有一个varchar(200)列,其中包含诸如,
ABC123124_A12312
ABC123_A1212
ABC123124_B12312
AC123124_AD12312
A12312_123
等等..
我想用一个数字替换一个数字序列,*以便我可以对表格中的不同非数字模式进行分组。
这个集合的结果是
ABC*_A*
ABC*_B*
AC*_AD*
A*_*
我在下面编写了以下原始查询,它可以正常工作,但是在一张大表上运行需要很长时间。
我需要帮助重写或编辑它以提高它的性能。SQL Server 2014
-- 1. replace all numeric characters with '*'
-- 2. replace multiple consecutive '*' with just a single '*'
SELECT REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE(SampleID, '0', '*'),
'1', '*'),
'2', '*'),
'3', '*'),
'4', '*'),
'5', '*'),
'6', '*'),
'7', '*'),
'8', '*'),
'9', '*')
, '*', '~*') -- replace each …Run Code Online (Sandbox Code Playgroud) sql-server pattern-matching sql-server-2014 string-manipulation query-performance
我们在这里使用 charindex 来搜索一个字符串,如下所示
SELECT *
FROM tablename
WHERE ( Charindex('47a%$.abc',CAST(columnname AS VARCHAR(MAX)))>0 )
Run Code Online (Sandbox Code Playgroud)
我打算用 LIKE 替换 charindex,因为我只需要搜索模式是否存在而不是位置。所以我想知道在我的情况下使用 LIKE 而不是 charindex 有什么缺点。我在几种情况下使用 charindex。所以我希望它适用于所有 sql 数据类型,包括特殊字符在内的所有字符(包括 %(就像已经使用了 %pattern%)。所以请告诉我使用 like 超过 charindex 有什么缺点
postgresql ×3
sql-server ×2
t-sql ×2
index ×1
my.cnf ×1
mysql ×1
performance ×1
select ×1
substring ×1
unaccent ×1