0

I have this query:

INSERT INTO ella (id, tmstmp AS DATE, ändere)
VALUES (id 1, DATE 26.08.2020,10:44:33, ändere "Thomas");

but it always show error: missing comma. What do I do wrong? Where else should I put the comma)

The table name is Ella. The column names are id, date, and ändere. Thank you for your help!

ella widya
  • 15
  • 5

2 Answers2

3

You need to enclose non-numeric values in single quotes and the column list doesn't take a data type. Names with non-ASCII characters need to be enclosed in double quotes in SQL. String literals need single quotes. The column names are also not repeated in the VALUES clause. And as you want to specify a date and time, you need to use a timestamp literal, not a date literal.

INSERT INTO ella (id, tmstmp, "ändere")
VALUES (1, timestamp '2020-08-26 10:44:33', 'Thomas');

All of the above refers to standard ANSI SQL and this would work in e.g. Postgres and Oracle. Not all DBMS products support ANSI timestamp literals that way though. But as you haven't specified your DBMS, the answer complies with the SQL standard.

1

it is likely your database expects a date following the ISO8601 format, which is: 2020-08-26 10:44:33.

Also, the values shall not repeat the column names, simply the values in the order of the keys, and finally, to quote strings, you shall use a single quote:

INSERT INTO ella (id, tmstmp, ändere)
VALUES (1, '2020-08-26 10:44:33', 'Thomas');

N.B.: the format of the date might depend on the database you're using, the above should work with postgresql, with a timestamp field.

N.B.2: finally, be careful with the timezone, and whether the timestamp you store is in UTC timezone or not, or you might get unexpected results.

zmo
  • 24,463
  • 4
  • 54
  • 90