16
payb4k
7y

Please use normalization. Don't store more than is intended in one field and use special characters to separate things. It would make future developers job easy.

Comments
  • 1
    Oh my god... 😟
  • 1
    Oh my eyes, the blood is pouring out.

    At least shove json in there if your going to do that kind of satanic crap.
  • 1
    I wish I could say otherwise, but that nothing. I was doing some work on a cash register. Old receipts were stored in the database... In the following manner in a single column

    HP 250€ 449,001€ 449,00Logitech M220€ 14.2€ 28.003.5mm to 6.5mm jack€0.52 €1Wireless adapter€320 €60

    Which was actually a list of
    1 HP 250 @€449,00 subtotal: €449,00
    2 Logitech M220 @€14 sub: €28,00
    2 3.5>6.5mm jack @ €0.5 sub: €1,00
    20 Wireless adapter@€3 sub: €60

    You couldn't even regex the shit out of it. There has to be some kind of validation
    Eg:
    221 is that 1 time €22 or is that 21 times €2, you could only see by the subtotal.

    It was hell.
  • 3
    If that is what I think it is, RIP op. It might be easier to start from scratch 😀
  • 0
    Nothing wrong with that. Its a row containing a array/list. If you know the amount of items in such a list, its easy to create a column for each item. However, if you don't know - for example, number of items in a receipt, its better to do like in OP's post.

    However, for receipts its better to use like:
    Item_amounts = "2,1,2"
    item_names = "bread,butter,salami"
    item_prices = "2,1.5,2.5"

    Which would be equvalient of:
    2 pcs of Bread for 2$ each = 4$
    1 pcs of Butter for 1.5$ each = 1.5$
    2 pcs of Salami for 2.5$ each = 5$

    Total: 10.5$

    Its however important to use a sensible delimiter AND filter input from any occurences of delimiter.
  • 1
    @sebastian yes, that's what I'm trying to say, there was no delimiter.only thing you could hope was that the subtotal had 2 decimals, and if not that the next item didn't start with a number.

    Needless to say, there is json in that column now
  • 0
    @sebastian Yeah, I've had to do something similar to the picture. My system tracks certain events which might contain an arbitrary amount of subevents. Most concise way is to store like OP, or use "field_name" and "field_value" along with some sort of unique identifier. Not very readable in database though.
Add Comment