is there a way to duplicate a row in a DB?
thnaks in advance
peleg
duplicating a row in a DB
Moderator: General Moderators
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Although I truly agree with McGruff that this is a waste of space, an integrity, logic and conflict risk, here is an example:
I'm not a database expert but this query does the trick. Btw I'm using PostgreSQL.
SCOrphus.
Code: Select all
test=> select * from holyday; idholyday | who | from_date | to_date | fd_hd
-----------+----------+------------+------------+-------
1 | william | 2004-12-30 | 2004-12-30 | pm
2 | william | 2004-12-31 | 2004-12-31 | am
3 | patricia | 2004-12-31 | 2004-12-31 | am
4 | caroline | 2004-12-31 | 2004-12-31 | fd
5 | john | 2004-12-31 | 2004-12-31 | fd
6 | patricia | 2004-12-31 | 2004-12-31 | am
7 | william | 2004-12-31 | 2004-12-31 | am
(7 rows)
test=> insert into holyday values((select max(idholyday)+1 from holyday), (select who from holyday where idholyday = 2), (select from_date from holyday where idholyday = 2), (select to_date from holyday where idholyday = 2), (select fd_hd from holyday where idholyday = 2));
INSERT 17224 1
teste=> select * from holyday; idholyday | who | from_date | to_date | fd_hd
-----------+----------+------------+------------+-------
1 | william | 2004-12-30 | 2004-12-30 | pm
2 | william | 2004-12-31 | 2004-12-31 | am
3 | patricia | 2004-12-31 | 2004-12-31 | am
4 | caroline | 2004-12-31 | 2004-12-31 | fd
5 | john | 2004-12-31 | 2004-12-31 | fd
6 | patricia | 2004-12-31 | 2004-12-31 | am
7 | william | 2004-12-31 | 2004-12-31 | am
8 | william | 2004-12-31 | 2004-12-31 | am
(8 rows)
test=>SCOrphus.