----------------------------------------
BACKGROUND:
My company (www.glass.biz) keeps information about products in a
network-shared (samba) filesystem. Each product has assigned to it
directory, and there our engineers save informations for ERP system.
This information is gathered by travelling whole directory structure
and reading text files. Our engineers work whole days producing more
and more information about new products (individual orders).
----------------------------------------
REAL PROBLEM:
Now I want to make ERP system faster and more reliable by using
PostgreSQL. But one question arrives I can't answer on myself nor by
googling around.
Every period of time (for example 1 day, 1 hour, or 1 minute) I will
have to synchronize my database with information stored in text files.
So how do I tell Postgres to:
1. insert row if data about product doesn't already exist in table
2. delete row if data about product was deleted from text files
3. update row if data has changed
----------------------------------------
MY SOLUTIONS:
1. Start transaction. For each entry in text file do:
-- use SELECT to check if entry exists
-- if entry exists update values
-- if entry doesn't exist insert values
Commit transaction.
In this solution rows that should be deleted are not deleted
and this is wrong. Furthermore I do select for each entry,
and this could take very long, so I think this is not good
solution.
2. Start transaction. Delete all rows from table.
Insert rows from text file. Commit transaction.
In this solution everything works okey, but I think this is
strange to replace whole table by encapsulating it into
transaction. From documentation I know that Postgres will
keep old rows until vacumm is done.
----------------------------------------
I would be very grateful if someone experienced would
advise any reasonable solution.
Leszek Dubiel