使用空格作为具有剪切命令的分隔符(use space as a delimiter with cut command)
我想用空格作为分隔符与
cut
命令。我可以用什么语法?
I want to use space as a delimiter with the
cut
command.What syntax can I use for this?
原文:https://stackoverflow.com/questions/816820
最满意答案
TL;博士
不要将BETWEEN用于字符串
其中drink_name> ='G'和drink_name <'P';
为什么?
O有效地扩展了尾随空格以匹配列。 所以
'O '
在此之前
'Oh My Gosh'
所以你需要
where drink_name BETWEEN 'G' and 'OZ';
如果你有一种名为
Ozymandias
的饮料,那么这将无效。 所以:where drink_name BETWEEN 'G' and 'OZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';
但是,我们可以安全地假设没有叫
P
和许多空间的饮料吗?
这是不可理解的。select drink_name from easy_drinks where drink_name BETWEEN 'G' and 'P';
显而易见的选择可能是仅使用LEFT比较第一个字母
select drink_name from easy_drinks where LEFT(drink_name, 1) BETWEEN 'G' and 'O';
但这会阻止在drink_name上使用任何索引。
tl;dr
Don't use BETWEEN for strings
where drink_name >= 'G' and drink_name < 'P';
Why?
The O is effectivly expanded with trailing spaces to match the column. So
'O '
is before
'Oh My Gosh'
So you'd need
where drink_name BETWEEN 'G' and 'OZ';
If you have a drink called
Ozymandias
then this won't work. So:where drink_name BETWEEN 'G' and 'OZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';
But, can we can safely assume that there is no drink called
P
and many spaces?
This is not understandable.select drink_name from easy_drinks where drink_name BETWEEN 'G' and 'P';
The obvious choice might be to compare only first letters using LEFT
select drink_name from easy_drinks where LEFT(drink_name, 1) BETWEEN 'G' and 'O';
But this will prevent used of any index on drink_name.
相关问答
更多-
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
TL;博士 不要将BETWEEN用于字符串 其中drink_name> ='G'和drink_name <'P'; 为什么? O有效地扩展了尾随空格以匹配列。 所以 'O ' 在此之前 'Oh My Gosh' 所以你需要 where drink_name BETWEEN 'G' and 'OZ'; 如果你有一种名为Ozymandias的饮料,那么这将无效。 所以: where drink_name BETWEEN 'G' and 'OZZZZZZZZZZZZZZZZ ...
-
大家都知道,我设法在上述项目中实现了这一点。 所以,如果有人感兴趣,他/她可以在那里找到它。 Just so everyone know, I managed to implement this in the mentioned project. So if anyone's interested he/she can find it there.
-
START TRANSACTION; Select apples from fruit where apples = 'golden' FOR UPDATE; ... COMMIT; SELECT ... FOR UPDATE语句首先锁定行,然后将其返回给您。 任何试图同时对同一行做同样事情的人都会等待你的COMMIT或ROLLBACK ,然后他们会收到你所做的任何改变的行...... 如果您无意更改行,您只想确保没有其他人可以,那么您可以SELECT ... LOCK IN SHARE ...
-
使用case-expression ,如下面的缩写示例所示: update table set color= case when black then "black" when red then "red" when blue then "blue" end; 这是一个平方米 Use a case-expression, as in this abbreviated example: update table set color= ...
-
按标签进行独家过滤(Exclusive filtering by tag)[2022-11-14]
这是我为自己找到的解决方案。 未经修改,它只能在Rails 3(或更高版本)中使用。 在Tag模型中: scope :find_by_names, lambda { |names| unless names.empty? where("tags.name IN (#{Array.new(names.length, "?").join(",")})", *names) else where("false") end } 在问题模型中: scope :tagged_with ... -
mysql中的独占读锁(exclusive read locks in mysql)[2022-09-04]
你应该做的是: 获得独占的写锁 选择要处理的行 将其状态更改为“处理”(或“可用”以外的其他内容) 解锁桌子 完成对行的所有处理 更新行以将其状态更改回“可用” 这将允许其他进程同时处理其他行。 它使表保持锁定足够的时间,以防止它们尝试在同一行上工作。 What you should do is: Get an exclusive write lock Select the row you want to process Change its status to "processing" (or somet ... -
SQL独占或插入(SQL exclusive or on insert)[2022-05-07]
你想要什么被称为“检查约束”。 不幸的是,MySQL不支持它们。 好吧,它会让你定义它们,但它实际上不会检查它们。 本文讨论使用触发器实现相同的功能。 What you want is called a "CHECK constraint". Unfortunately, MySQL does not support them. Well, it will let you define them, but it won't actually check them. This article discusse ... -
MySQL独占行选择(MySQL exclusive row select)[2022-07-21]
在这种情况下使用JOIN而不是嵌套查询通常是有益的: SELECT sp.order_id FROM survey_product AS sp LEFT JOIN (SELECT order_id FROM survey_product WHERE product_id = 20) AS sp_t ON sp.order_id = sp_t.order_id WHERE sp_t.order_id IS NULL AND ... -
MySQL选择检测组内互斥的行冲突(MySQL select to detect mutually exclusive row conflicts within groups)[2022-02-10]
这应该工作: select distinct item, `desc` from table group by item, `desc` HAVING count(distinct data1) > 1 or count(distinct data2) > 1 or count(distinct data3) > 1 This should work: select distinct item, `desc` from table group by item, `desc` HAVING count( ...