I can't insert a date
into a PostgreSQL 9.6 table.
This is the INSERT Query:
INSERT INTO rates (idproperty, from, to, price)
VALUES (1, '2017-03-14', '2017-04-30', 130);
And that's the result:
ERROR: syntax error at or near "from"
LINE 1: INSERT INTO rates (idproperty, from, to, price)
The columns from
and to
are defined with the data type date
.
Thanks
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With