error: time zone "gmt-0500" not recognized
See original GitHub issueI am doing a simple INSERT INTO
query. The database column in question is of type TIMESTAMPTZ
. Here is my code segment:
let date_created = Date();
const res = await db.query(
`INSERT INTO testtable1 (date_created
VALUES ('${date_created}')`
);
Which produces an error:
time zone "gmt-0500" not recognized
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Error: Timezone "gmt+0200" is not recognized - Stack Overflow
Forgot to say I'm using PostgreSQL. ADate column is type "timestamp without time zone", earlier it was "timestamp with time zone" but I...
Read more >Re: Time zone "GST" not recognized. - PostgreSQL
ERROR : time zone "GST" not recognized SQL state: 22023. Try GMT: test_(postgres)# select CURRENT_TIMESTAMP AT TIME ZONE 'GMT'; timezone
Read more >Time tooltips incorrectly display time zones - GitLab.org
The problem lies with the dateFormat v3.0.3 library as it will render the time zone incorrectly. The problem can be traced back to...
Read more >Working with dates and timezones in JavaScript - Ursa Health
JavaScript's internal representation uses the “universal” UTC time but by the time the date/time is displayed, it has probably been localized ...
Read more >Incorrect timezone being fetched using Date javascript API.
Chrome does not recognise the Time Zone in line 8 (left side of the pic). Intl datetime with local tz in line 4...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Date()
returns a string. To create aDate
object, you neednew Date()
.And also, identifiers (table names, column names) cannot be parameterized in an SQL query, so your
query2
should be something like:Or simply
INSERT INTO "testtable"
, instead of using a variable. The key thing here is that you don’t use a placeholder for it; the same way you don’t use placeholders for the column names.Note that, with this way of building up a query,
tables.users
should never be accepted as user input (e.g. from the POST body of an HTTP request). If it is user input, you’ll have to do more a lot more to guard against SQL injection. For example, with the query I’ve provided, an attacker could do something like this to delete all the data in the table: