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

  • Home
  • SEARCH
  • 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 8681667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:34:14+00:00 2026-06-12T21:34:14+00:00

My database is separated into schemas based on clients (i.e.: each client has their

  • 0

My database is separated into schemas based on clients (i.e.: each client has their own schema, with same data structure).

I also happen to have an external action that does not know which schema it should target. It comes from another part of the system that has no concepts of clients and does not know in which client’s set it is operating. Before I process it, I have to find out which schema that request needs to target

To find the right schema, I have to find out which holds the record R with a particular unique ID (string)

From my understanding, the following

SET search_path TO schema1,schema2,schema3,...

will only look through the tables in schema1 (or the first schema that matches the table) and will not do a global search.

Is there a way for me to do a global search across all schemas, or am I just going to have to use a for loop and iterate through all of them, one at a time?

  • 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-12T21:34:15+00:00Added an answer on June 12, 2026 at 9:34 pm

    You could use inheritance for this. (Be sure to consider the limitations.)

    Consider this little demo:

    CREATE SCHEMA master;  -- no access of others ..
    
    CREATE SEQUENCE master.myseq;  -- global sequence for globally unique ids
    
    CREATE table master.tbl (
      id int primary key DEFAULT nextval('master.myseq')
    , foo text);
    
    CREATE SCHEMA x;
    CREATE table x.tbl() INHERITS (master.tbl);
    INSERT INTO  x.tbl(foo) VALUES ('x');
    
    CREATE SCHEMA y;
    CREATE table y.tbl() INHERITS (master.tbl);
    INSERT INTO  y.tbl(foo) VALUES ('y');
    
    
    SELECT * FROM x.tbl;  -- returns 'x'
    SELECT * FROM y.tbl;  -- returns 'y'
    SELECT * FROM master.tbl;  -- returns 'x' and 'y' <-- !!
    

    Now, to actually identify the table a particular row lives in, use the tableoid:

    SELECT *, tableoid::regclass AS table_name
    FROM   master.tbl
    WHERE  id = 2;
    

    Result:

    id | foo | table_name
    ---+-----+-----------
    2  | y   | y.tbl
    

    You can derive the source schema from the tableoid, best by querying the system catalogs with the tableoid directly. (The displayed name depends on the setting of search_path.)

    SELECT n.nspname 
    FROM   master.tbl   t
    JOIN   pg_class     c ON c.oid = t.tableoid
    JOIN   pg_namespace n ON c.relnamespace = n.oid
    WHERE  t.id = 2;
    

    This is also much faster than looping through many separate tables.

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

Sidebar

Related Questions

My product uses a SQL Server database - each client has their own deployed
Our data model is separated into schemas on two databases. The schemas are used
I have the following data in my database (comma separated strings): word, test, hello
We are designing database schema for a new system based on Oracle 11gR1. We
Good Morning All, I have loaded over 1,300 blurbs into my client's database with
In my database I have three schemas: Schema1 Schema2 Schema3 Objects are separated out
HI all! My client currently has a SQL Server database that performs 3-4 Million
I am getting records from database as comma separated. I am getting contact titles
There is a column in database which contains comma separated values like: 0.00,12.45,14.33 and
I have a field in my database that contain comma separated values these values

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.