Inserting date into PostgreSQL: Columns from and to
I believe you have used postgresql reserved words - from
and to
to create your table. In order to use them in your query, they need to be enclosed in quotes "
Try it this way:
INSERT INTO rates (idproperty, "from", "to", price)
VALUES (1, '2017-03-14', '2017-04-30', 130);
from
and to
are reserved words in PostgreSQL. You need to escape them with "
:
-- This fails:
test=# SELECT from FROM rates;
ERROR: syntax error at or near "FROM"
LINE 1: SELECT from FROM rates;
^
-- This works:
test=# SELECT "from" FROM rates;
from
------
(0 rows)
See list of reserved words: https://www.postgresql.org/docs/current/static/sql-keywords-appendix.html