transfer data
Hi!
I have two tables:
Table A:
article_number, count
a 2
b 5
g 3
Table B:
article_number, count
b 7
Now I want to transfer 2 units of b and 3 units of g from Table A to table
B. So the result should be:
Table A:
article_number, count
a 2
b 3
g 0 (or empty line)
Table B:
article_number, count
b 9
g 3
What is the best way to do this transaction with postgresql? I've tried to do
this with update and insert statements from psql but I'm sure there is a
better way!?
ciao
Detlef
--
# Dipl. Ing. (FH) Detlef Jockheck
# E-mail: detlef@jockheck.de
# -------------------------------
nope, update and insert are it.
OR, you could put it all in one table with an additional column that had
status's like 'A', and 'B', and have a unique index on (article_number, status),
but it would still involve inserts and updates. How else is data changed?
You could abstract it by writing a PL/PGSQL function that was named something
like change_status_of_articles( article_number, old_status, new_status), and
that would make life easier AFTER you wrote the function. BUT, the function
would have all the same things in it that you've been writing by hand; You just
wouldn't have to do anything but run the function after that.
Detlef Jockheck wrote:
Show quoted text
Hi!
I have two tables:
Table A:
article_number, count
a 2
b 5
g 3Table B:
article_number, count
b 7Now I want to transfer 2 units of b and 3 units of g from Table A to table
B. So the result should be:Table A:
article_number, count
a 2
b 3
g 0 (or empty line)Table B:
article_number, count
b 9
g 3What is the best way to do this transaction with postgresql? I've tried to do
this with update and insert statements from psql but I'm sure there is a
better way!?ciao
Detlef