Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have some values under "account" and I need to have the same values under "invoice", so, I'm trying to find a way to symlink my tables, so every time one gets updated, the another have the new value too. I'm developing under OpenERP, I can't trow that update directly on code, I need to write the rule using PgAdmin or something like.

I need to junction symlink 2 tables under Postgres.

ACCOUNT                INVOICE  
|ID|payment_type|@@@@@@|ID|account_payment_type|  
|#1|cc          |@@@@@@|#1|cc                  |  
|#2|cash        |@@@@@@|#2|cash                |  
|#3|cash        |@@@@@@|#3|cash                |  
share|improve this question
add comment

2 Answers

From your example it seems like invoice can be replaced with a simple VIEW, which is similar to a "symlink" in nature:

CREATE VIEW invoice AS
SELECT id, account_payment_type FROM account;

All done.
Else you need to be more specific in your question. Start with providing the complete table definition for both tables and add more information what is covered in each ...

share|improve this answer
    
Ok, I'll try to use that view. Many thanks. Next time I'll try to provide more info about the tables and the system. –  Tonon Jun 10 '13 at 18:28
    
Can I create a table from a view? –  Tonon Jun 10 '13 at 19:44
    
Sure you can. But that would defeat it's purpose, wouldn't it? Since you seem to understand that metaphor: it's lake making a hard copy from a symlink in the file system. Except if you mean in the sense of a materialized view? There is a new feature for that in the upcoming version 9.3 btw. –  Erwin Brandstetter Jun 10 '13 at 20:16
add comment

At a guess, if a simple view doesn't meet your needs for whatever reason, maybe you're looking for triggers?

Add an AFTER ... FOR EACH ROW trigger on each table that does the INSERT, UPDATE or DELETE on the other table. You'll want to write it in PL/PgSQL. For details, see the PostgreSQL documentation on triggers.

Otherwise, maybe you want an updatable view? You can achieve that with a DO INSTEAD view trigger. Again, see the Pg docs.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.