Datetime field overflow 7 error date time field value out of range

I am importing a csv file into a PostgreSQL database. Most of the file imports without any trouble until I get this message ERROR: date/time field value out of range: "1421088300" HINT: Perhaps ...

Seconds since epoch timestamps

Your «timestamp» is in seconds-since-epoch. Per dezso, use to_timestamp(). I missed that when I checked dfS+

Bad complex idea, and dragons.

Check the input formats. They cover casts from strings. That’s what COPY is doing under the hood. The only method that even remotely looks like a long number is ISO 8601. If you look at that example though you’ll see it’s not a seconds-since-epoch

Example    | Description
19990108   | ISO 8601; January 8, 1999 in any mode

This is basically the same as another example on that chart.

Example    | Description
1999-01-08 | ISO 8601; January 8, 1999 in any mode

Converting to timestamp with abstime as an intermediary format

So if you want to convert from seconds-since-epoch, you can cheat by using the internal abstime since there is no available cast directly to timestamp from a string of seconds-since-epoch.

SELECT 1421088300::abstime::timestamp;
      timestamp      
---------------------
 2015-01-12 12:45:00
(1 row)

What’s happening here is that abstime is binary coercable with integer. You can see that in dC+. I checked dfS+ for functions to get from integer to timestamp and found none. There is a cast though from integer to abstime (which is stored as an integer), and from abstime to timestamp.

If this is a new table you could actually type that column as abstime. It should load perfectly fine. And then you can ALTER TABLE. here is an example, except I’m not running COPY (but it should work all the same).

CREATE TABLE foo(bar)
AS VALUES
  (1421088300::abstime);

TABLE foo;
          bar           
------------------------
 2015-01-12 12:45:00-06
(1 row)

ALTER TABLE foo
  ALTER bar
  TYPE timestamp;

TABLE foo;
         bar         
---------------------
 2015-01-12 12:45:00
(1 row)

d foo;
                Table "public.foo"
 Column |            Type             | Modifiers 
--------+-----------------------------+-----------
 bar    | timestamp without time zone | 

I’m trying to cast a varchar into a date with this following code, and the following error is outputting, any idea why?

ALTER TABLE import.employee
ALTER COLUMN birth_date
TYPE date
USING (birth_date::date);

    ERROR:  date/time field value out of range: "05/29/1960"
HINT:  Perhaps you need a different "datestyle" setting.
********** Error **********

ERROR: date/time field value out of range: "05/29/1960"
SQL state: 22008
Hint: Perhaps you need a different "datestyle" setting.

asked Apr 27, 2014 at 20:55

DodoSombrero's user avatar

Set the datestyle before:

set datestyle = mdy;

answered Apr 27, 2014 at 21:08

Clodoaldo Neto's user avatar

Clodoaldo NetoClodoaldo Neto

115k25 gold badges225 silver badges250 bronze badges

2

If you need to get the ::date from birth_date, first give the DATE format to your field using the given functions in Data Type Formatting Functions docs.

answered Apr 27, 2014 at 21:25

Sergio B.'s user avatar

  • Remove From My Forums
  • Question

  • I am trying to run the Select query(linked server) from SSMS to get the data from PostgreSQL on AWS cloud. My query is running fine in SSMS but as soon as I enter the following line of code

    and c.created_date >=concat(to_char(CURRENT_DATE — interval ‘7 day’, ‘yyyy-mm-dd’),’ 00:00:00′):: timestamp 
    and c.created_date <= concat(to_char(CURRENT_DATE — interval ‘1 day’,’yyyy-mm-dd’) ,’ 23:59:59′) ::timestamp 

    it starts giving me ERROR: date/time field value out of range: «2020-06-0700:00:00»;

    created_date field in my PostgreSQL is timestamp without timezone

    Which datatype should I chose which is compatible with SQL Server?

    • Edited by

      Sunday, June 14, 2020 6:28 AM

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Datestyle postgresql как изменить
  • Datatables warning table id table ajax error
  • Datastore usage on disk vmware ошибка
  • Datasource error запрос был прерван не удалось создать защищенный канал ssl tls подробные сведения
  • Datasource error запрос был прерван не удалось создать защищенный канал ssl tls power query

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии