title: Missing month and day in Postgresql
body: <p>I have Date values, few dates are complete (format: yyyy-mm-dd but as text, not in date format), but few dates are having missing month and missing day value,
  for which now I will have to add the missing month and day. Example: if day is missing, first of that month has to be added to the date and if month and day are missing 1st of jan has to be added to the year part, In sql I was able to concatenate simply with the number as following: </p>
  
  <pre><code>CASE  WHEN LENGTH(&lt;t&gt;1.CMSTDT) = 4  THEN TO_DATE(&lt;t&gt;1.CMSTDT ||'-01-01','YYYY-MM-DD')  
  WHEN LENgTH(&lt;t&gt;1.CMSTDT) = 7  THEN TO_DATE(&lt;t&gt;1.CMSTDT ||'-01','YYYY-MM-DD')  
  ELSE TO_DATE(SUBSTR(&lt;t&gt;1.CMSTDTC\,1,10),'YYYY-MM-DD') END
  </code></pre>
  
  <p>Now Similar concatenation must be done in POSTGRESQL and I tried using CAST and to_char and few other functions, but I was unable to concatenate the values, can anyone help me on this.I am very new to POSTGRESQL, I am not aware which function to use in this case.</p>
  
  <p>Yes, that 1.CMSTDT is a date part which is used in SQL not in POSTgresql, My results has to look like this:</p>
  
  <pre><code>Actual Values   Results 
  2014-06         2014-06-01
  1998-08         1998-08-01
  1986            1986-01-01
  </code></pre>