One Retool database entry is duplicating in the table view

I have a table in my app that is displaying all the shipping information from a table in my database. This morning I entered some new data through a form I had created and everything went fine until I got to the last record.

The last record I entered appeared twice in the app table. I went to the data to make sure it was not a double entry and it was not. It is only in the database once. The really strange thing is that whatever I do to one of the duplicated record happens to the other. I tried changing the shipping date in one and they both changed and then both showed up on that date.

It only seems to be happening for this one record. Does anyone have any idea what would be causing that?

2 Likes

Hey @tomm :wave:

Just a guess here: could it be that the joins you're making at a query level are returning two different rows for the same id??

You could see the state of your query for those two records and see if all the fields and nested values are equal or if there is one that is different and that could be producing this.

I think it is expected that changes made to one row change the other as they will both have the same primary id.

I checked both databases and I only find one record in each that matches the query. I'll check the state of the query and see what that reveals.

UPDATE: I just went and ran the query and the duplicate record is now just one record. I'm not sure what happened as I did not make any changes.

2 Likes

Hi @tomm, I'm glad to hear the issue went away. It may have been a small UI bug. Please let us know if this happens again.

Happy building! :hammer_and_pick:

@Paulo,

Actually it has happened again. As I have been going through the records in the shipping schedule table, I have noticed at least 3 records so far that show up twice. Again, they don't show up in the database twice, just the table view.

When I highlight one of the records, they both highlight. If I try to update a cell in one of the records, the cell in the other record also updates with the same value. It's like a ghost record because even though I can make changes to one of the records, it will not let me do anything with the other. If I delete one, they both delete. It's very strange and would definitely put this project in jeopardy.

Any help you could provide would be most appreciated.

Hey @tomm,

I've seen the highlight behavior (two identical rows) happening whenever my data source has duplicates in the primary key and the highlighted rows have matching primary keys (which in itself shouldn't happen).

Any chance you're able to share the query that returns the data you are using as data source of your table? My uninformed guess is that you may be applying some joins that return two rows for the same id from the first table being fetched?

1 Like

@MiguelOrtiz

Here is is:

SELECT *
FROM shipping
  LEFT JOIN pools_built ON shipping.serial_num = pools_built.sequence
WHERE ({{ !date79.value }} OR ship_date = {{ date79.value }})
ORDER BY ship_date, load_num, load_order, dealer

Ok, I don't know your data structure, but try making it an outer join, i.e.

SELECT *
FROM shipping
  LEFT OUTER JOIN pools_built ON shipping.serial_num = pools_built.sequence
WHERE ({{ !date79.value }} OR ship_date = {{ date79.value }})
ORDER BY ship_date, load_num, load_order, dealer

@MiguelOrtiz, it worked! Some SQL programmer I am. I didn't even catch that. Thank you so much for your assistance. You've been a real life saver in this project.

1 Like

I'm glad that worked @tomm ! My heart sank when you mentioned your project could be in jeopardy (I've been there too!). All the best!

1 Like