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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:25:52+00:00 2026-06-17T16:25:52+00:00

I am trying to create one view (or view in each schema to be

  • 0

I am trying to create one view (or view in each schema to be used without modifications) on table which exists in multiple schemas with the same name

create schema company_1;
create schema company_2;
...
CREATE TABLE company_1.orders
(
  id serial NOT NULL,
  amount real,
  paid real,
  CONSTRAINT orders_pkey PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);

CREATE TABLE company_2.orders
(
  id serial NOT NULL,
  amount real,
  paid real,
  CONSTRAINT orders_pkey PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);

....

What is correct way of creating view on table orders without specifying schema for every view or specifying current schema?

What I need and failed to get is either

CREATE OR REPLACE VIEW
public.full_orders AS
SELECT id, amount FROM orders;

or

CREATE OR REPLACE VIEW
company_1.full_orders AS
-- company_2.full_orders AS
-- company_n.full_orders AS
SELECT id, amount FROM current_schema.orders;

Using postgresql 9.2.2

EDIT: The way I went:

CREATE VIEW company_1.full_orders AS
SELECT id, amount FROM company_1.orders;

On schema copy discussed here I butaly do this

FOR src_table IN 
   SELECT table_name 
   FROM information_schema.TABLES 
   WHERE table_schema = source_schema AND table_type = 'VIEW'
LOOP
    SELECT view_definition 
    FROM information_schema.views 
    WHERE table_name = src_table AND table_schema = source_schema INTO q;
    trg_table := target_schema||'.'||src_table;
    EXECUTE 'CREATE VIEW ' || trg_table || ' AS '||replace(q, source_schema, target_schema);
END LOOP;

Still looking for better solution…

  • 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-17T16:25:53+00:00Added an answer on June 17, 2026 at 4:25 pm

    It’s not possible to do with with a straightforward view. The view records the underlying table’s identity at creation time, so it is not affected by schema settings done later on.

    You could do it using a set-returning function using dynamic SQL, and then wrap that into a view. But I don’t think that’s a good solution.

    I would just create quasi-duplicates for the view, as you have been doing, and enhance my deployment script to keep them all up to date.

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

Sidebar

Related Questions

I am trying to create a table view, in which the table view cells
I'm trying to create horizontal scroll view(s). Each view containing one image. [done] Initially
I am trying to create a table where one of the columns has a
i'm trying to create a portfolio website using wordpress, each post has view costum
I am trying to create a grid view containing multiple rows and columns of
I am trying to create multiple records with two collections that i have View
Hi guys i am trying to create one simple make file and execute in
I am new to xslt and trying to create one XSLT , I am
I'm trying to create cookie from one folder that will also work in another.
I am trying to create two separate sessions- one for if the user is

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.