question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error: time zone "gmt-0500" not recognized

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
charmandercommented, Jan 12, 2020

Date() returns a string. To create a Date object, you need new Date().

0reactions
joelmukuthucommented, Jan 12, 2020

And also, identifiers (table names, column names) cannot be parameterized in an SQL query, so your query2 should be something like:

let query2 = {
  text: `
    INSERT INTO "${tables.users}"
      (uid, username, email, email_verified, date_created, last_login, password)
    VALUES ($1, $2, $3, $4, $5, $6, $7)
  `,
  values:
    [0, 'a', 'a@a.com', false, date_created, last_login, 'a']
  };

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:

const tables = { 
  users: 'testtable" (uid) values (1);delete from testtable;insert into "testtable' 
};
const query = { text: `INSERT INTO "${tables.users}" ...`
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found