Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 366827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:40:10+00:00 2026-05-12T13:40:10+00:00

I have the following table Table bots{ ip_address varchar(15), bot_name varchar(32) } Given that

  • 0

I have the following table

Table bots{
    ip_address varchar(15),
    bot_name varchar(32)
}

Given that some bots have static ips and others won’t, the table has entries such as 192.168.0 and 192.168.1.15

Now I have to see if a given ip belongs to a bot. I was thinking something along these lines

SELECT bot_name
FROM bots
WHERE __input_ip__  REGEXP '^ip_address'

but this won’t work for the obvious reason that it is looking for a string that starts with ip_address.

So my question is, how can I include a field name within a sql regular expression ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:40:11+00:00Added an answer on May 12, 2026 at 1:40 pm

    You might want to consider storing the IP address as an INT UNSIGNED. Also store the netmask so you can tell the difference between a static address and a subnet.

    INSERT INTO bots (ipaddress, netmask, bot_name) 
    VALUES (INET_ATOI('192.168.1.0'), INET_ATOI('255.255.255.0'), 'Wall-E');
    

    Then you can query to see if an input IP address matches:

    SELECT bot_name
    FROM bots
    WHERE __input_ip__ & netmask = ipaddress & netmask;
    

    Using integers for IP addresses instead of CHAR(15) is a common optimization. Even storing the 8 bytes for the IP address and the netmask is little more than half the storage of the CHAR(15). And the bitwise operations are likely to be a lot faster than the regular expression matching, and it’s easier to avoid the corner cases like in @Gumbo’s comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: I am trying to create an SQL query that
I have two tables that have following rows: Table1 ID Name Number ===================== 1
I have the following table structure: Table Users ID | Name 1 | John
I have the following table structure + id + word + +------+--------+ The table
I have the following table in PostgreSQL 8.4.5: snake=> create table gps ( id
I have the following table: CREATE TABLE posting ( id integer NOT NULL PRIMARY
I have the following table with these columns: shortName, fullName, ChangelistCount Is there a
I have the following table and trigger but the trigger isn't setting the create_dt
I have the following table with 10 unique rows, BookingID is a FK containing
I have the following table structure: +----------+------------------------+------+-----+------------------------------------------+----------------+ | Field | Type | Null |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.