Обсуждение: copy a record from one table to another (archive)
Hello there Is it possible to move a record from one table to another to do a archive with a simple command like move .... ? Thanks .... jr ============================================ PFISTER + PARTNER, SYSTEM - ENGINEERING AG Juerg Rietmann Grundstrasse 22a 6343 Rotkreuz Switzerland phone: +4141 790 4040 fax: +4141 790 2545 mobile: +4179 211 0315 ============================================
----- Original Message ----- From: <juerg.rietmann@pup.ch> To: <pgsql-sql@postgresql.org> Sent: Tuesday, March 13, 2001 12:45 PM Subject: [SQL] copy a record from one table to another (archive) > Hello there > > Is it possible to move a record from one table to another to do a archive > with a simple command like move .... ? > begin; insert into archive_foo (select * from foo where foo_id=1); delete from foo where foo_id=1; commit; Is probably the closest you could get. Alternatively, you could wrap the above up in a function and just go: select do_archive_foo(1); - Richard Huxton
Thus spake Richard Huxton
> begin;
> insert into archive_foo (select * from foo where foo_id=1);
> delete from foo where foo_id=1;
> commit;
>
> Is probably the closest you could get.
>
> Alternatively, you could wrap the above up in a function and just go:
>
> select do_archive_foo(1);
Or even use a trigger if suitable. You can have the delete automatically
trigger an insert into another table.
--
D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.