sql-like

Pandas text matching like SQL's LIKE?

不羁的心 提交于 2019-12-03 09:34:34
Is there a way to do something similar to SQL's LIKE syntax on a pandas text DataFrame column, such that it returns a list of indices, or a list of booleans that can be used for indexing the dataframe? For example, I would like to be able to match all rows where the column starts with 'prefix_', similar to WHERE <col> LIKE prefix_% in SQL. You can use the Series method str.startswith (which takes a regex): In [11]: s = pd.Series(['aa', 'ab', 'ca', np.nan]) In [12]: s.str.startswith('a', na=False) Out[12]: 0 True 1 True 2 False 3 False dtype: bool You can also do the same with str.contains

SWITCH with LIKE inside SELECT query in MySQL

时光怂恿深爱的人放手 提交于 2019-12-03 09:29:59
I have this Tags table CREATE TABLE IF NOT EXISTS `Tags` ( `id_tag` int(10) unsigned NOT NULL auto_increment, `tag` varchar(255) default NULL, PRIMARY KEY (`id_tag`), UNIQUE KEY `tag` (`tag`), KEY `id_tag` (`id_tag`), KEY `tag_2` (`tag`), KEY `tag_3` (`tag`), KEY `tag_4` (`tag`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2937 ; INSERT INTO `Tags` (`id_tag`, `tag`) VALUES (1816, '(class'), (2642, 'class\r\n\r\nâ?¬35'), (1906, 'class\r\nif'), (1398, 'class'), (2436, 'class)'), (1973, 'class:\n1.'), (2791, 'classes'), (1325, 'New'), (2185, 'pack'), (1905, 'packed'), (1389, 'WebClass');

SQL Not Like Statement not working

天大地大妈咪最大 提交于 2019-12-03 09:20:23
I have the following code within a stored procedure. WHERE WPP.ACCEPTED = 1 AND WPI.EMAIL LIKE '%@MATH.UCLA.EDU%' AND (WPP.SPEAKER = 0 OR WPP.SPEAKER IS NULL) AND WPP.COMMENT NOT LIKE '%CORE%' AND WPP.PROGRAMCODE = 'cmaws3' The NOT LIKE statement is not working, and yes before anyone says anything there are items with the COMMENT column that does not include CORE and all the other columns are ok. Does anyone know what is wrong with this? If WPP.COMMENT contains NULL , the condition will not match. This query: SELECT 1 WHERE NULL NOT LIKE '%test%' will return nothing. On a NULL column, both

NOT LIKE and LIKE not returning opposite result

空扰寡人 提交于 2019-12-03 09:17:15
I have a table with 200 records out of which 10 records has text containing the word 'TAX'. When I'm executing Select * from tbl1 WHERE [TextCol] LIKE '%TAX%' then I get the result set with those 10 records correctly . But when I am trying to exclude those records by Select * from tbl1 WHERE [TextCol] NOT LIKE '%TAX%' it's returning 100 records only, instead of 190. Does this return the correct result ? Select * from tbl1 WHERE COALESCE([TextCol],'-1') NOT LIKE '%TAX%' I believe NULL values are the issue here, if the column contains them, then NULL NOT LIKE '%TAX%' will return UNKNOWN/NULL and

How to ignore characters on a MYSQL SELECT LIKE %…%

我是研究僧i 提交于 2019-12-03 09:10:49
问题 I have a table with a phone column, where data may have spaces, dots,dashes or + signs between the numbers. I need to do a search with LIKE wildcards that ignore all those characters, for example: a record may have phone as "+123-456 78.90" a query looking for "6789" or any complete or incomplete sequence of proper digits in order should bring up that record. Unfortunately I cant cleanup the original table to remove the non-digit characters and do a plain SELECT LIKE %...%. MYSQL has

Full text search vs LIKE

只愿长相守 提交于 2019-12-03 08:32:16
问题 My question is about using fulltext.As I know like queries which begin with % never use index : SELECT * from customer where name like %username% If I use fulltext for this query can ı take better performance? Can SQL Server use fulltext index advantages for queries like %username%? 回答1: Short answer There is no efficient way to perform infix searches in SQL Server, neither using LIKE on an indexed column, or with a fulltext index. Long answer In the general case, there is no fulltext

SQL SELECT LIKE (Insensitive casing)

我怕爱的太早我们不能终老 提交于 2019-12-03 08:06:31
问题 I am trying to execute the sql query: select * from table where column like '%value%'; But the data is saved as 'Value' ( V is capital ). When I execute this query i don't get any rows. How do i make the call such that, it looks for 'value' irrespective of the casing of the characters ? 回答1: use LOWER Function in both (column and search word(s)). Doing it so, you assure that the even if in the query is something like %VaLuE%, it wont matter select qt.* from query_table qt where LOWER(column

Hive query with multiple LIKE operators

风流意气都作罢 提交于 2019-12-03 07:30:23
What would be the right way to write a Hive query with multiple LIKE operators like this: SELECT * FROM some_table WHERE some_col LIKE '%abc%' OR some_col LIKE '%xyz%' OR some_col LIKE '%pqr%' OR ... (some more LIKE statements) I tried doing the above as well as WHERE some_col LIKE '%abc|pqr|xyz%' but they didn't return any results. It works fine if I write separate queries, i.e. WHERE some_col LIKE '%abc%' -> returns results and WHERE some_col LIKE '%pqr%' -> also returns results From the docs: A RLIKE B NULL if A or B is NULL, TRUE if any (possibly empty) substring of A matches the Java

SQLite: Should LIKE 'searchstr%' use an index?

試著忘記壹切 提交于 2019-12-03 04:57:24
问题 I have a DB with several fields word_id — INTEGER PRIMARY_KEY word — TEXT ... ..and ~150k rows. Since this is a dictionary, I'm searching for a word with mask 'search_string%' using LIKE. It used to work just fine, taking 15ms to find matching rows. The table has an index for a field 'word' . Recently I've modified the table (some fields of that table which are out of the scope) and something happened — it's taking 400ms to execute query, so I understand that as it fails to use index now.

MySQL: NOT LIKE

限于喜欢 提交于 2019-12-03 04:04:30
问题 I have these text in my db, categories_posts categories_news posts_add news_add And I don't want to select the rows with categories , I use a query something like this, SELECT * FROM developer_configurations_cms WHERE developer_configurations_cms.cat_id = '1' AND developer_configurations_cms.cfg_variables LIKE '%parent_id=2%' AND developer_configurations_cms.cfg_name_unique NOT LIKE '%categories%' but it returns these two in the output as well... categories_posts categories_news How can I