1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【React】invalid input syntax for type timestamp with time zone エラーの解決方法

Posted at

はじめに

位置情報をテーブルへ保存する際以下のエラーが表示され、そちらの解決法について記事にします。

下記のエラーが表示されました。

位置情報保存エラー invalid input syntax for type timestamp with time zone: "Tue Apr 15 2025 18:31:58 GMT+0900 (日本標準時)"

【修正前】下記のように記述していました。

.tsx
// users_locationテーブルに位置情報挿入
      if (userId) {
        const { error } = await supabase.from('users_location').upsert({
          id: userId,
          location: `SRID=4326;POINT(${longitude} ${latitude})`,
          updated_at: new Date().toString()
        }, { onConflict: 'id' })
        if (error) {
          console.error('位置情報保存エラー', error.message)
          toast.error('位置情報の保存に失敗しました');
        }
      }

テーブルもこちらで作成していました。

.SQL
updated_at timestamp with time zone default now()

解決方法

テーブルの型に合わせISO形式に変換する

.tsx
// users_locationテーブルに位置情報挿入
      if (userId) {
        const { error } = await supabase.from('users_location').upsert({
          id: userId,
          location: `SRID=4326;POINT(${longitude} ${latitude})`,
          updated_at: new Date().toISOString()
        }, { onConflict: 'id' })
        if (error) {
          console.error('位置情報保存エラー', error.message)
          toast.error('位置情報の保存に失敗しました');
        }
      }

参考

おわりに

time zoneについて学ぶことができました。


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?