Your error seems to clearly state what the problem is:
ERROR: invalid input syntax for type timestamp: ""
It appears your query is trying to insert an empty string into a PostgreSQL field that has a type of 'timestamp'. If you were inserting an invalid string of some sort, it should appear in the error that you are recieving like:
ERROR: invalid input syntax for type timestamp: "foobardtimestamp"
Or, in your case, if your expected string was being passed, your error may look like this:
ERROR: invalid input syntax for type timestamp: "2002-03-11"
...but the error doesn't say that which makes me suspect your string isn't actually getting passed to the query like you think. The fact is, as previously pointed out: PostgreSQL should be perfectly capable of handling 2002-03-11
as a valid timestamp string.
PostgreSQL doesn't like inserting '' (empty string) as a timestamp and will complain with the error that you provided.
If you want to provide an empty string, you need to be sure you don't have a NOT NULL
constraint on the column, and you need to use null
instead of an empty string. If you aren't meaning to send an empty string, I would check on the value of $pdo->quote($date)
to make sure you're getting the string that you want returned from that.
You can also try to output your generated SQL before you actually run the query to make sure it looks correct. I have a feeling, if you do, it will look something like this:
INSERT INTO dates(date) VALUES('')
Also, for what it's worth, your example says you're running:
$pdo->query($date);
when I'm fairly certain you want: $pdo->query($query);