M
M
mmind2021-01-31 12:14:32
PostgreSQL
mmind, 2021-01-31 12:14:32

How to fix data type error?

I make a request

INSERT INTO data.source(id, created, created_utc) VALUES($1, to_timestamp('$2'), to_timestamp('$3'))

I get an error
error: invalid input syntax for type double precision: "$2"


What's wrong? In my database, the type of this field is timestamp , and he rubs me about double .
Inserted Value 1581569438

In the documentation , to_timestamp takes double precision - is n't the number I'm returning a double ? (I do it in js, forced this value to a number) to_timestamp(double precision)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-01-31
@mmind

For some reason, the value of the variable "$2" is not substituted in your code and the string '$2' is transferred to the database, not a number.
Have a look at SQL fiddle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question