I am using the following code
$rooms = $room->join('events', 'LEFT')
->on('rooms.id', '=', 'events.room_id')
->where('events.room_id', 'IS', NULL)
->and_where_open()
->and_where('events.eventstart' , '>', $from)
->or_where('events.eventsstart', '<', $to)
->and_where_close()
->find_all();
echo $room->last_query(); exit;
But in query i get > instead of > sign
SELECT `rooms`.* FROM `rooms`
LEFT JOIN `events` ON (`rooms`.`id` = `events`.`room_id`)
WHERE `events`.`room_id` IS NULL
AND (`events`.`eventstart` > 1312401600 OR `events`.`eventsstart` < 1312408800)
Dont know why???
My Mistake
The column name used in or_where was wrong. Thats why i was getting > sign in my query
Thanks Kemo for guiding me in other direction.
Related
Now, I have some results from JSON parse to SQL, and where clause is different with postgresql.
Then, need to convert with regex or replace it, but I am not familiar with regex.
SELECT Column_name, Column_name_2, Column_name_3 FROM sample WHERE LIKE(Column_name_2, "text") OR LIKE(Column_name_2, "text_2") OR LIKE(Column_name_2, "text_3") OR LIKE(Column_3, cwcwsd) LIMIT 100;
Output:
SELECT Column_name, Column_name_2, Column_name_3 FROM sample WHERE Column_name_2 LIKE "text" OR Column_name_2 LIKE "text_2" OR Column_name_2 LIKE "text_3" OR Column_name_2 LIKE cwcwsd LIMIT 100;
Alternative approach is to create a PostgreSQL function LIKE(text, text):
create or replace function LIKE(text, text)
returns boolean
language sql
AS $$
SELECT $1 LIKE $2;
$$;
Test it:
SELECT LIKE('success', 'su%');
Returns true;
I tried to use REPLACE to delete some words, like 'HOMEMAKER' and 'HOUSEWIFE', from strings. But I failed to change those words into empty space. Why is that happening?
I want to delete strings like 'HOMEMAKER' and 'HOUSEWIFE' from column EMPLOYER using REPLACE function but failed. I also tried REGEXP_REPLACE but failed again. These are the table I have (Sorry I want to build a table here but somehow it doesn't work).
EMPLOYER
RETIRED/HOMEMAKER
HOMEMAKER/HOMEMAKER
SELF-EMPLOYED/HOMEMAKER
We code is listed below:
SELECT EMPLOYER,
CASE WHEN EMPLOYER LIKE '%HOUSE%WIFE%'
THEN REGEXP_REPLACE(EMPLOYER,r'HOUSE%WIFE',' ')
WHEN EMPLOYER LIKE '%HOME%MAKER%'
THEN REGEXP_REPLACE(EMPLOYER, r'HOME%MAKER', ' ')
ELSE '0'
END AS SIGN
FROM fec.work
WHERE EMPLOYER LIKE '%HOME%MAKER%'
OR EMPLOYER LIKE '%HOUSE%WIFE%'
GROUP BY 1,2;
The result I want is like:
SIGN
RETIRED/
/
SELF-EMPLOYED/
But I got exactly the same columns in SIGN as EMPLOYER. Can anyone tell me why replace function did not make any changes?
You should use something like below
REGEXP_REPLACE(EMPLOYER, r'HOUSEWIFE|HOMEMAKER',' ')
you can use i flag to make this replacement case insensitive
REGEXP_REPLACE(EMPLOYER, r'(?i)HOUSEWIFE|HOMEMAKER',' ')
Either of these options should work for your case.
with test as (
select 'EMPLOYER' as my_str union all
select 'RETIRED/HOMEMAKER' as my_str union all
select 'HOMEMAKER/HOMEMAKER' as my_str union all
select 'SELF-EMPLOYED/HOMEMAKER' as my_str
)
select
my_str,
REPLACE(REPLACE(my_str, 'HOUSEWIFE', ' '), 'HOMEMAKER', ' ') as replaced_str,
REGEXP_REPLACE(my_str, r'HOUSEWIFE|HOMEMAKER', ' ') as regexed_str
from test
I have a field named field, and I would like to see if it is null, but I get an error in the query, my code is this:
let
Condition= Excel.CurrentWorkbook(){[Name="test_table"]}[Content],
field= Condition{0}[fieldColumn],
query1="select * from students",
if field <> null then query1=query1 & " where id = '"& field &"',
exec= Oracle.Database("TESTING",[Query=query1])
in
exec
but I get an error in the condition, do you identify the mistake?
I got Expression.SyntaxError: Token Identifier expected.
You need to assign the if line to a variable. Each M line needs to start with an assignment:
let
Condition= Excel.CurrentWorkbook(){[Name="test_table"]}[Content],
field= Condition{0}[fieldColumn],
query1="select * from students",
query2 = if field <> null then query1 & " some stuff" else " some other stuff",
exec= Oracle.Database("TESTING",[Query=query2])
in
exec
In query2 you can build the select statement. I simplified it, because you also have conflicts with the double quotes.
I think you're looking for:
if Not IsNull(field) then ....
Some data types you may have to check using IsEmpty() or 'field is Not Nothing' too. Depending on the datatype and what you are using.
To troubleshoot, it's best to try to set a breakpoint and locate where the error is happening and watch the variable to prevent against that specific value.
To meet this requirement, I would build a fresh Query using the PQ UI to select the students table/view from Oracle, and then use the UI to Filter the [id] column on any value.
Then in the advanced editor I would edit the generated FilteredRows line using code from your Condition + field steps, e.g.
FilteredRows = Table.SelectRows(TESTING_students, each [id] = Excel.CurrentWorkbook(){[Name="test_table"]}{0}[fieldColumn])
This is a minor change from a generated script, rather than trying to write the whole thing from scratch.
I am trying to search and replace a specific text in a column in mssql based on specific search criteria. I am simply getting it wrong.
I have tried to use the 2 examples from this thread but cant get it right - Updating serialised array in mysql (without unserialising?)
note wp_postmeta is the table name and meta_value is the column name
SET #search = 'View Map +';
SET #replace = 'View New Map2 +';
UPDATE wp_postmeta SET meta_value=REPLACE(meta_value, CONCAT('s:',
LENGTH(#search), ':"', #search, '"'), CONCAT('s:', LENGTH(#replace), ':"',
#replace, '"')) WHERE `meta_id` = 170442
I am getting this error
MySQL returned an empty result set (i.e. zero rows)
I have also tried this second option but it still fails
$old = 'View Map +';
$new = 'View New Map2 +';
$search = 's:' . strlen($old) .':"' . $old . '"';
$replace = 's:' . strlen($new) .':"' . $new . '"';
$query = "UPDATE wp_postmeta SET meta_value=REPLACE(meta_value,
'{$search}','{$replace}') WHERE `meta_id` = 170442 and
meta_value LIKE '%View Map +%';";
I am getting this error
$old = 'View Map +';
MySQL said:
Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '$old =
'View Map +''at line 1
Any ideas?
Thank you
I was scratching my head over this but the above option 1 works fine now.. I did not have the whole array in the search and replace box but part of it thus the error
I am using the below code to search the class name abc in the HTML code:
nodes = doc.DocumentNode.SelectNodes("//*[contains(concat(' ', normalize-space(#class), ' '), ' abc ')]");
Which is giving me correct result.
But if I want to search ID name abc instead of Class, the above code is not working.
Maybe the code which I am using contains #class word hence it is not working for ID names.
Is there any way to search both "Class" and "ID" names using same code?
First of all, ID is different than id. HTML is case-insensitive, but XML is case-sensitive. Take a look at this answer from Simon Mourier, the author of HtmlAgilityPack.
That said, when you use its XPATH feature, you must use tags written
in lower case. It means the "//body" expression will match BODY, Body
and body, and "//BODY" will match nothing.
The same stands for ID.
Regarding the filter logic, you have to use the Logical-and operator:
var nodes = doc.DocumentNode.SelectNodes(
"//*[contains(concat(' ', normalize-space(#class), ' '), ' abc ')"+
" and " +
"contains(concat(' ', normalize-space(#id), ' '), ' div1 ')]");
Or, simpler:
var nodes = doc.DocumentNode.SelectNodes("//*[#class=\"abc\" and #id=\"div1\"]");
But as a personal preference, if the context allows it, I would use LINQ to do it:
var nodes = doc.DocumentNode.Descendants()
.Where(i =>
i.Attributes["class"] != null
&& i.Id != null
&& i.Attributes["class"].Value == "abc"
&& i.Id == "div1");