PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 24th, 2003, 05:34 AM
ottonelli ottonelli is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 1 ottonelli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Join with tables in different db

I have to join fields in two tables that are in two different db.
Is it possible to do that in postgresql, and how can I do that?
Thanks.

Reply With Quote
  #2  
Old June 24th, 2003, 06:39 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
Short answer: no.

Long answer: yes, IIRC, there is a plugin available in contrib that allows this. Do a search on the postgres site as I don't remember what it's called off the top of my head.

Reply With Quote
  #3  
Old June 24th, 2003, 10:11 AM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 58 sec
Reputation Power: 17
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
It's called dblink.
__________________
PostgreSQL, it's what's for dinner...

Reply With Quote
  #4  
Old June 24th, 2003, 11:35 AM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 60
Another thing to remember: if you use PostgreSQL 7.3+, you can use schemas to make one database "seem" like multiple databases, including the ability to query between them.

Really, this is not a cheap hack. Schemas are widely used in Oracle and other high-end systems, and they really are different databases from the user's perspective, so there is no reason not to take advantage of schemas.
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #5  
Old June 24th, 2003, 12:53 PM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 58 sec
Reputation Power: 17
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
I don't mean to thread hijack, but if rycamor doesn't mind I'd like to hear some pros and cons for separate database vs. schemas, and possible cases of misusing/overusing schemas.

For example, I can see placing all intranet apps in one database separated by different schemas for app specific info to centralize authentication and general info (emp info, dept info). Would this be a reasonable idea? If so, when would separating into different databases be more feasible (besides just having totally unrelated data).

Also, how does using schemas have any adverse affects to db maintenance. For example longer vacuums (when doing the whole db as opposed to a specific table), vacuum fulls taking down the whole database, etc.?


-b

Reply With Quote
  #6  
Old June 24th, 2003, 01:40 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 60
Quote:
Originally posted by bcyde
I don't mean to thread hijack, but if rycamor doesn't mind I'd like to hear some pros and cons for separate database vs. schemas, and possible cases of misusing/overusing schemas.

For example, I can see placing all intranet apps in one database separated by different schemas for app specific info to centralize authentication and general info (emp info, dept info). Would this be a reasonable idea? If so, when would separating into different databases be more feasible (besides just having totally unrelated data).

Schemas are nothing more than nesting of "subdatabases". As of version 7.3, you are always using a schema, even if it is the default "public" schema. Think of schemas exactly the same way you would think of namespaces in a programming language. For example, PHP5 might have namespace support, which would allow many related classes to all be called under one namespace, rather than pollutin the global namespace. Thus you could have a "Geometry" namespace, with a class called "radius", and you could have a "Geography" namespace, with its own class "radius". Now, with PHP4 you could just fake namespaces by doing something like

geom_radius
geom_chord
geom_circumference

and

geog_radius
geog_circumference

You get the idea. But it is a very inelegant way to solve the problem, and doesn't prevent operations in one area of concern from accessing operations in the other, since they are all available globally. Namespaces usually come with a few other features, such as the ability to prevent a class from being accessed by anything except other classes in its namespace, etc...

So, schemas allow you to do exactly the same kind of separation, and all aspects of a schema are under the control of the user/group permissions system. Thus, depending on who you are when you log into the database, you see different schemas available to you. Each schema is essentially a nested database, with its own complete set of tables, views, etc... BUT (here's the fun part) views, queries, triggers, etc... can span multiple schemas, as long as the user permissions are resolved properly.

A cool example might be if you are providing a remote service where multiple customers each have their own database, but you as the "admin" need the ability to query everyone's "transaction_log" table. Well, then you can define a view in the "admin" schema that joins each of the other tables with a UNION, so they all look like one large table to you.

Quote:

Also, how does using schemas have any adverse affects to db maintenance. For example longer vacuums (when doing the whole db as opposed to a specific table), vacuum fulls taking down the whole database, etc.?


I doubt this is a serious consideration except for very large databases. Yes, you do lose physical independence of each database, but remember, pg_dump can be run on schemas instead of the whole DB, and VACUUM is schema-aware, so you should be able to do VACUUM FULL myschema.*, or something like that.

Reply With Quote
  #7  
Old June 25th, 2003, 03:36 PM
metaBarf metaBarf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 373 metaBarf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 6 sec
Reputation Power: 10
may there be security issues or data backup issues in having multiple schemas as opposed to seperate instances of a db?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Join with tables in different db

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap