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 8176795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:19:49+00:00 2026-06-06T23:19:49+00:00

In my database table(whitelist_domain_data) I have the fields id,url,data The Url column has multiple

  • 0

In my database table(whitelist_domain_data) I have the fields id,url,data

The Url column has multiple urls like

http://www.dailystrength.org/c/Hidradenitis_Suppurativa/forum/8870995-solodyn-135-mg-works
http://au.answers.yahoo.com/question/index?qid=20090325215905AA6UVOa
http://navaspot.wordpress.com                                                              

I want to fetch the rows which have the same domain.

TABLE : Whitelist_domain_data

Schemas : id,url,data

select regexp_matches(url,'http\:\/\/([a-z0-9\.]+)\.org')  as domain,
       count(*) 
from whitelist_domain_data 
group by domain;

Should return:

dailystrength.org   200

Ques:
How to design the query to fetch all the urls data,if the url has the domain “dailystrength.org”?

  • 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-06-06T23:19:52+00:00Added an answer on June 6, 2026 at 11:19 pm

    You can do this with substring(), and you’ll also probably want to use an expression index. Here’s an example (I tweaked the regex to match what I think you want):

    CREATE TABLE whitelist_domain_data(
      id SERIAL PRIMARY KEY,
      url TEXT NOT NULL
    );
    
    CREATE INDEX domain_index
      ON whitelist_domain_data (substring(url from 'https?\:\/\/([a-z0-9\.]+)'));
    
    INSERT into whitelist_domain_data (url) VALUES
      ('http://www.dailystrength.org/c/Hidradenitis_Suppurativa/forum/8870995-solodyn-135-mg-works'),
      ('http://au.answers.yahoo.com/question/index?qid=20090325215905AA6UVOa'),
      ('http://navaspot.wordpress.com');
    
    SELECT * FROM whitelist_domain_data WHERE substring(url from 'https?\:\/\/([a-z0-9\.]+)') = 'www.dailystrength.org';
    

    Now this query can use the index. If this is something you plan on using a lot, you might consider also creating a specific function for it:

    CREATE FUNCTION get_domain(text) RETURNS text
    LANGUAGE SQL
    AS $$
      SELECT substring($1 from 'https?\:\/\/([a-z0-9\.]+)');
    $$;
    

    Then the above becomes:

    CREATE INDEX domain_index
      ON whitelist_domain_data (get_domain(url));
    
    SELECT * FROM whitelist_domain_data WHERE get_domain(url) = 'www.dailystrength.org';
    

    So then if you ever want to change what a domain is (to ignore subdomains, or whatever) you can just change the function and your queries will all still work. I think you’ll have to reindex at that point, though.

    I checked that this all works on Postgres 9.1, but it should be compatible with any recent version. Expression indexes and substring() both go back to the 7.x days.

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

Sidebar

Related Questions

In database table I have column called options . It has type of integer
the database table has fields like this: fld_column1 fld_column1_item_1 fld_column1_item_2 fld_column1_item_3 fld_column2 fld_column2_item_1 fld_column2_item_2
I have a database table structure as follow: datatype data mytable now datatype has
I have a database table that has a structure like the one shown below:
I have a User database table that has the following fields, Id Username Password
I have one large database table of request data, much like Apache request logs,
I have a database table that has two fields , date and name. I
A database table named users has a column timemarks . The timemark fields look
Say I have a database table like the following: FileID | FileName | FileSize
Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products'

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.