0

trying to add a row with timestamp for my table which consists of

time timestamp without time zone NOT NULL

I'm using the function now(), but I keep getting

ERROR: invalid input syntax for integer: "2016-12-09 14:32:14.111332"

I tried now()::timestamp didn't help either any idea?

CREATE TABLE game (
   score integer,
   score2 integer,
  time timestamp without time zone NOT NULL,
  CHECK ((score is NULL) and (score is NULL)) 
);

insert into game values(2,3,now()); Thanks!

9
  • Use single quotes for (text) literals " '2016-12-09 14:32:14.111332' Commented Dec 9, 2016 at 12:41
  • so i can't use the now function? Commented Dec 9, 2016 at 12:44
  • that didn't help either Commented Dec 9, 2016 at 12:45
  • invalid input syntax for integer What is the integer here ? Commented Dec 9, 2016 at 12:45
  • 1
    Try insert into game (score, score2, time) values(2,3,now()); Unrelated, but: time is a horrible name for a column - even worse for a timestamp column. Commented Dec 9, 2016 at 12:54

2 Answers 2

1

I think your problem resides on the CHECK...

I tested your query with few tweaks and it worked.

Working script:

CREATE TABLE game (
  score integer,
  score2 integer,
  time2 timestamp without time zone NOT NULL,
  CHECK ((score is NOT NULL) and (score2 is NOT NULL)) 
);

Check working example here

P.s As user @Raul mentioned, be careful with variable names to not use reserved words, time may get you into trouble

Sign up to request clarification or add additional context in comments.

Comments

0

My best guess is that 2016-12-09 14:32:14.111332 is not recognized as an ISO standard.

ISO 8601 uses the 24-hour clock system. The basic format is [hh][mm][ss] and the extended format is [hh]:[mm]:[ss]. Accepted would be: hh:mm:ss.sss, hh:mm:ss or hh:mm.

What bothers me is all those numbers at the end: 2016-12-09 14:32:14.111332 14.111332, I don't recall seeing timestamps like this, I might be wrong.

Maybe try inserting 2016-12-09 14:32:14 and see if it throws the same error. Also the name of the column should be changed, column with names the same as some keywords can cause statements to fail.

3 Comments

It's not it. I think i figured it out.. Might be some problem with a function i wrote..
Cool, maybe post the answer also, if you find it. Would be helpful for others that have the same problem.
Also as an advice, be more careful when naming columns, you might have some trouble inserting in a column with the name date, I think time is also in the same spot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.