i have missing records in a sequence and my current output looks like this
| 1882 | 25548860 | 4 | 30 | null | null |
| 1882 | 25548861 | 4 | 30 | null | null |
| 1882 | 25548882 | 4 | 30 | null | null |
| 1882 | 25548883 | 4 | 30 | null | null |
| 1882 | 25548884 | 4 | 30 | null | null |
| 1882 | 25548885 | 4 | 30 | null | null |
missing records in between until 2122
| 2122 | 25548860 | 4 | 30 | null | null |
| 2122 | 25548861 | 4 | 30 | null | null |
| 2122 | 25548882 | 4 | 30 | null | null |
| 2122 | 25548883 | 4 | 30 | null | null |
| 2122 | 25548884 | 4 | 30 | null | null |
| 2122 | 25548885 | 4 | 30 | null | null |
I want my output to be in below format. Suggest me a sql query that will update the records in monetdb between 1883 to 2121.
| 1882 | 25548860 | 4 | 30 | null | null |
| 1882 | 25548861 | 4 | 30 | null | null |
| 1882 | 25548882 | 4 | 30 | null | null |
| 1882 | 25548883 | 4 | 30 | null | null |
| 1882 | 25548884 | 4 | 30 | null | null |
| 1882 | 25548885 | 4 | 30 | null | null |
| 1883 | 25548860 | 4 | 30 | null | null |
| 1883 | 25548861 | 4 | 30 | null | null |
| 1883 | 25548882 | 4 | 30 | null | null |
| 1883 | 25548883 | 4 | 30 | null | null |
| 1883 | 25548884 | 4 | 30 | null | null |
| 1883 | 25548885 | 4 | 30 | null | null |
........ ..........
........ ..........
| 2122 | 25548860 | 4 | 30 | null | null |
| 2122 | 25548861 | 4 | 30 | null | null |
| 2122 | 25548882 | 4 | 30 | null | null |
| 2122 | 25548883 | 4 | 30 | null | null |
| 2122 | 25548884 | 4 | 30 | null | null |
| 2122 | 25548885 | 4 | 30 | null | null |
If you know in advance the range of missing
id
s, you can usegenerate_series()
. Assuming that your table is calledmytable
and has columns(id, col1, col2, col3, col4, col5)
, you can duplicate the records that haveid
1882 to fill the gap with the following query: