Given a table cc_playlist
with 4 row/records where id_key
is the primary key that auto increments, and track_id
, track_position
and playlist_id
:
+--------+----------+----------------+-------------+
| id_key | track_id | track_position | playlist_id |
+--------+----------+----------------+-------------+
| 23 | 3 | 0 | 1 |
| 223 | 23 | 1 | 1 |
| 343 | 45 | 2 | 1 |
| 344 | 32 | 3 | 1 |
+--------+----------+----------------+-------------+
Problem:
When I wish to add a new record, e.g. track_id = 777
,track_position=2
, playlist_id =1
, I want it to place the new record and push the rest of the records down, as long as it is in the same playlist_id
.
+--------+----------+----------------+-------------+ | id_key | track_id | track_position | playlist_id | +--------+----------+----------------+-------------+ | 23 | 3 | 0 | 1 | | 223 | 23 | 1 | 1 | -->| 345 | 777 | 2 | 1 | | 343 | 45 | 3 | 1 | | 344 | 32 | 4 | 1 | +--------+----------+----------------+-------------+
NOTE: I am doing this in php, If it can't be done in Postgres.