public String toSqlString() {
    if (type == Type.IDENT) {
      return name;
    }
    else if (value == null) {
      return "NULL";
    }
    else if (type == Type.STRING) {
      return Utils.quoteString((String)value);
    }
    else if (type == Type.TIMESTAMP) {
      int len = 19;
      String t = ((Timestamp) value).toString();   // .0 returned if the fractional part not set
      if (scale > 0) {
        len += scale + 1;
      }
      if (t.length() > len) {
        t = t.substring(0, len);
      }
      return String.format("TIMESTAMP '%s'", t);
    } else if (type == Type.DATE) {
      return String.format("DATE '%s'", ((Date) value).toString());
    }
    return toString();
  }
Convert value to SQL string - string literals are quoted and escaped, ab'c -&gt; 'ab''c'
hplsql/src/main/java/org/apache/hive/hplsql/Var.java