6 kyu

Present XML data the SQL way

Description
Loading description...
Fundamentals
SQL
Data Science
  • Please sign in or sign up to leave a comment.
  • vicad Avatar

    Great kata! Forced me to google how to work with XML data.

  • gRubies Avatar

    Excellent practice and a good reason to delve deeper into the work of postgreSQL with xml.

  • ooscmdeejay Avatar

    Can someone please tell me if the email is empty input the xpath function will return NULL as place holder or no in the array? Everything is fine but only the order of the email address I can't solve it.

  • Infuzibil Avatar

    This comment has been hidden.

  • drakel Avatar

    I am new too querying XML and got stuck because I kept getting the error "PG::CardinalityViolation: ERROR: more than one value returned by column XPath expression". This appeared to be caused because there were multiple values that could be returned from the XML path '/data/user/email_addresses/address'. Its a simple fix, and If anyone else gets stuck with this error, I finally tracked down an example of how handle multiple values here: https://www.ibm.com/docs/en/i/7.1?topic=table-using-xmltable-handle-multiple-values

  • EduOporto Avatar

    Attempting to tackle this kata, I got all the data right but the ages.

    What I'm doing is an age(actual_date, born_date). I guess the problem is on the tests, as they were calculated from a different date as the one I'm calculating now. Anyway, I can't think about any other way of calculating the ages, as I don't know when those tests where generated.

    Maybe it could be good to have some sort of a reference date to calculate the ages, in order to make the results match with the tests. Otherwise I can't see how people could tackle this kata

    • FArekkusu Avatar

      Firstly, random tests always use today as the reference point, it is your approach of explicitly specifying 2021-06-18 that is bad. Secondly, your solution is wrong as it incorrectly "generates" the date_of_birth - the extraction itself produces correct values but string-to-date conversion is always off:

       extracted | converted
      ------------------------
      1994-12-28 | 1993-11-02
      1999-11-28 | 1998-11-01
      1998-12-28 | 1997-11-02
      1998-11-11 | 1997-11-01
      1998-12-13 | 1997-11-02
       2000-11-6 | 1999-11-01
       1997-3-27 | 1996-08-04
       1998-11-4 | 1997-11-01
       1992-10-7 | 1991-11-01
       1999-7-27 | 1998-04-03
        1992-4-4 | 1991-07-27
             ... | ...
      
      Suggestion marked resolved by FArekkusu 4 years ago
  • inigosainz Avatar

    I'm having issues to produce 'Hidden' for the email address when the profile is private ... Could someone help with this part? Any hint will be most welcome

    Below the results I'm able to produce:

    first_name | last_name | age | email_address John | Doe | 23 | john.doe14825@domain.com Johnatan | Doe | 25 | johnathan.doe68245@domain.com Johny | Doe |27 | johny.doe97218@domain.com Jon Doe | 21 | johny.xoxo@domain.com

    Thanks

    • FArekkusu Avatar

      I'm having issues to produce 'Hidden'

      Extract the private field and check its value - all you need is a simple conditional expression. In your place I'd be more worried about assigning email addresses to wrong people, like Jon has the second Johny's email address listed as his own. I've changed the sample tests to use different names, so if you reset the trainer, you'll see the issue clearly.

  • ZED.CWT Avatar
    Results: Actual 
    Elijah    Anderson    24    mihppaozdbtrz@domain.com
    Elijah    Anderson    24    opzybxpegwxacm@domain.com
    
    Results: Expected
    Elijah    Anderson    24    opzybxpegwxacm@domain.com
    Elijah    Anderson    24    mihppaozdbtrz@domain.com
    

    I did not capture the original data, but i guess they have the identical date_of_birth

    • FArekkusu Avatar

      Changed it so that a list of unique dates is generated. Idk if there's a reliable way to confirm it works correctly.

    • FArekkusu Avatar

      Rewrote the tests to generate a list of shuffled unique names, so this shouldn't be a problem anymore.

      Issue marked resolved by FArekkusu 5 years ago