LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-04-2022, 09:37 AM   #1
glennbtn
Member
 
Registered: Dec 2009
Posts: 154

Rep: Reputation: 19
SQL Query help


Hi All

So I have a query I have written for my pbx to get data out, the script here works perfectly

Code:
select caller_id_number,caller_destination,destination_number,start_stamp from today_call_records WHERE start_stamp > now() - interval 5 minute AND direction = 'inbound' AND domain_name = 'pbx.mydomain.co.uk' AND destination_number NOT regexp '^([1000-1999])' AND destination_number NOT regexp '^([*90])' AND destination_number NOT regexp '^([*89])' AND destination_number NOT regexp '^([*88])' AND destination_number NOT regexp '^([*87])' AND destination_number NOT regexp '^([*86])' AND destination_number NOT regexp '^([*85])' AND destination_number NOT regexp '^([*84])' AND destination_number NOT regexp '^([*83])' AND hangup_cause NOT like 'USER_BUSY' ORDER BY start_stamp

Now I also need to exclude from the sql query *82 *81 & *80 but if I add any more eg another

Code:
AND destination_number NOT regexp '^([*82])'

Then I don't get any errors but also don't get any data. As soon as I remove the extra bit of query it works fine.

Is there some sort of limitation in the queries or is there anything I can do to resolve the issue

Thanks

Last edited by glennbtn; 08-05-2022 at 02:14 AM.
 
Old 08-04-2022, 09:51 AM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

I suspect the solution can be one or two simple regexes, but I'm making no attempt to read that query until you format it and use "[code]..[/code]" tags to preserve the formatting.

 
Old 08-04-2022, 10:01 AM   #3
glennbtn
Member
 
Registered: Dec 2009
Posts: 154

Original Poster
Rep: Reputation: 19
Oops, sorry not put code in before.

I have edited the original post

Thanks
 
Old 08-04-2022, 10:03 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
would be nice to know where did you enter this command. Is it command line? script? or ?
 
Old 08-04-2022, 10:17 AM   #5
glennbtn
Member
 
Registered: Dec 2009
Posts: 154

Original Poster
Rep: Reputation: 19
I have it in both a php script and also test it using table plus
 
Old 08-04-2022, 11:52 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Your 'extra' regexp is missing the end single-quote.
 
Old 08-05-2022, 02:13 AM   #7
glennbtn
Member
 
Registered: Dec 2009
Posts: 154

Original Poster
Rep: Reputation: 19
Hi chrism01

From the above yes I forgot the extra single quote but that's not missing when I add further examples. My issue is if I add anymore to the original query IE and extras

Code:
AND destination_number NOT regexp '^([*82])'
I fail to get anything from the database and no errors.
 
Old 08-05-2022, 02:20 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
what you posted is still not enough to diagnose. I can only guess: somehow/somewhere there was a line length limit set.
posting parts of a line without knowing anything about the context/environment is simply useless.
http://www.catb.org/~esr/faqs/smart-...html#beprecise
 
Old 08-05-2022, 02:36 AM   #9
lvm_
Member
 
Registered: Jul 2020
Posts: 942

Rep: Reputation: 338Reputation: 338Reputation: 338Reputation: 338
Regular expression ^([*82]) means 'all lines starting with *, 8 or 2 - is this what you really want? It's also a good idea to mention what kind of SQL you use and what flavour of regular expression in supports.
 
Old 08-05-2022, 02:47 AM   #10
glennbtn
Member
 
Registered: Dec 2009
Posts: 154

Original Poster
Rep: Reputation: 19
@pan64 the whole sql query is at the root of the question, nothing is missing from the query and it's not just part of a query

@lvm We are trying to track missed calls as the system does not do it correctly. From the report we need to exclude all the instances of eg *81 *82 *83 etc as these are features codes we have built in and are not missed calls as the customer has chosen them.
 
Old 08-05-2022, 03:16 AM   #11
lvm_
Member
 
Registered: Jul 2020
Posts: 942

Rep: Reputation: 338Reputation: 338Reputation: 338Reputation: 338
You didn't make it much clearer, but if by this you mean CDRs starting with '*81', '*82' and so on then your regexp should be '^\*8[1-3]', not what you typed. Wikipedia has a nice article about regular expressions, read it.
 
Old 08-05-2022, 03:40 AM   #12
glennbtn
Member
 
Registered: Dec 2009
Posts: 154

Original Poster
Rep: Reputation: 19
@lvm thanks. I did forget to put in that it was mariadb 10.1.48 sorry

I can't currently get it to work as getting a regex error but will go and take a look and try and get my head around it all.

Thanks again
 
Old 08-05-2022, 07:55 AM   #13
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by glennbtn View Post
I have edited the original post
All you've done is wrapped a query with no formatting in code tags.

The code tags preserve formatting (i.e. newlines and indents), you still need to add this to make it readable in the first place.

 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query help struct Programming 2 10-27-2010 12:29 AM
[SOLVED] Bash script: Need some help on how to parse a simple SQL query newbie_0404 Linux - Newbie 10 06-02-2010 12:31 AM
MYSQL: SQL query takes 10 minutes to execute. Need help optimizing. robel Programming 7 10-29-2008 04:44 PM
SQL query help pls. vickr1z Programming 8 10-18-2004 11:25 PM
help on finding the number that has max occurrences in a column [sql query] zeppelin Programming 6 06-15-2004 01:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration