0

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                |  

2 Answers 2

1

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 ...

3
  • 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, 2013 at 18:28
  • Can I create a table from a view?
    – Tonon
    Jun 10, 2013 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. Jun 10, 2013 at 20:16
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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