title: How to parse a string and create rows in SQL (postgres)
body: <p>I have a single database field that contains a start date, end date, and exclusions in the form </p>
  
  <pre>available DD/MONTH/YYYY [to DD/MONTH/YYYY]?[, exclude WORD [, WORD]*]?</pre>
  
  <p>Meaning it always starts with "available DD/MONTH/YYYY", optionally has a single "to DD/MONTH/YYYY", and optionally has an exclude clause that is a comma separated list of strings.  Think regular expression meanings for + , *, and ?</p>
  
  <p>I have been tasked with extracting the data out so we will now have a "startdate" column, "enddate" column, and a new table that will contain the exclusions.  It will need to fill the startdate and enddate columns with the values parsed from the availability string.  It will also need to create multiple records in the new exclusion table, one for each of the comma separate values after the 'exclude' key word in the availability string.</p>
  
  <p>Is this a migration I can do in SQL only (postgres 8.4)?</p>
  
  <p>This is against postgres 8.4.</p>
  
  <p><b>Update:</b> With the help of a co-worker we now have a sql script that has as it's results sql to perform the insert statements based on the parsing of the exclusions.  It uses a bunch of case statements and string manipulation within the sql to generate the results.  I then send the output to a file and execute that file to perform the inserts.  I am doing the same for the start and end date columns.</p>
  
  <p>It's not 100% sql, but a simple .bat or .sh file that runs the first .sql file, then the generated one is all that is needed to get it to go.</p>
  
  <p>Thanks for the input.</p>