Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 时间被存储在postgres数据库中,没有时区,即使我提供它们来续集_Postgresql_Sequelize.js - Fatal编程技术网

Postgresql 时间被存储在postgres数据库中,没有时区,即使我提供它们来续集

Postgresql 时间被存储在postgres数据库中,没有时区,即使我提供它们来续集,postgresql,sequelize.js,Postgresql,Sequelize.js,我正在使用sequelize在我的postgres数据库中填充一个表。我有一个带有时间数据类型的字段,但是没有存储时区。我正在做一个类似这样的工作: await models.Event.bulkCreate(events); 其中事件是我添加的新实例,以JSON格式格式化。 以下是其中一个实例的示例: { "_REMOVE_INFO": "App Development - Alessandro Ferrari", "City": "Milano",

我正在使用sequelize在我的postgres数据库中填充一个表。我有一个带有时间数据类型的字段,但是没有存储时区。我正在做一个类似这样的工作:

await models.Event.bulkCreate(events);
其中事件是我添加的新实例,以JSON格式格式化。 以下是其中一个实例的示例:

    {
        "_REMOVE_INFO": "App Development - Alessandro Ferrari",
        "City": "Milano",
        "Region": "MI",
        "Country": "Italy",
        "Address": "Via Massimo D'Azeglio, 3, 20154",
        "Date": "2020-11-21",
        "Time": "9:00 AM PST",
        "Title": "Code your idea ",
        "Pic": "https://images.pexels.com/photos/546819/pexels-photo-546819.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940",
        "Description": "You'll learn the basic building blocks of a website and how to style them. No previous coding experience needed.You will leave with the core concepts of HTML (tags, elements, and attributes), and the basics of CSS (selectors, properties, and values) and some Javascript. All your work will be in a platform that will allow you to code along with your instructor, and continue to work on it after you leave!",
        "MaxCapacity": 20,
        "Type": "Workshop"
    }
但是在我运行脚本之后,postgres没有存储数据的时区部分。事实上,它明确地表示“没有时区的时间”,如本截图所示:

在我的事件模型模式中,我定义时间如下

    Time: {
        type: DataTypes.TIME,
        allowNull: false,
    }
我的问题是存在于我格式化JSON的方式还是存在于我的Sequelize配置中?如何解决它?

。如果要使用时区存储时间,必须将列更改为该数据类型

但是不要。如果需要使用时区存储时间,请使用
时区时间戳
时间戳
。在Sequelize中,这是
.DATE

虽然日期类型不能有关联的时区,但时间类型可以。除非与日期和时间相关联,否则真实世界中的时区没有什么意义,因为偏移量可以随着夏令时边界的变化而变化

默认时区指定为UTC的恒定数值偏移量。因此,在跨DST边界执行日期/时间算术时,不可能适应夏令时

为了解决这些困难,我们建议在使用时区时使用同时包含日期和时间的日期/时间类型。我们不建议使用time with time zone类型(尽管PostgreSQL支持传统应用程序和SQL标准)。PostgreSQL假定任何类型的本地时区只包含日期或时间

例如,我所在的位置是-0700。我想把午餐时间定在中午。使用
timetz
,午餐时间为
12:00:00-0700
。再过几个月,夏令时就要结束了,我们将“倒退”一个小时到-0800。但午餐时间仍然是当地时间下午1点左右


如果我将午餐时间存储为
时间
12:00
将是正确的,无论时区如何。

您必须在数据类型**timestamp[(p)]中使用时区** 如果需要,请更改您的桌子

alter table table_name alter column column_name TIME with time zone;    

这里他们提到了时间数据类型:这是为了别的什么吗?非常彻底的回答。非常感谢。我将改为同时使用日期和时间。没有存储原始时区的数据类型。要做到这一点,您需要添加一个附加列。您是否用
sequelize
方言确定时区?我的sequrlize配置是这样的:`````开发:{“用户名”:“postgres”,“密码”:null,“数据库”:“myDb”,“主机”:“localhost”,“方言”:“postgres”,“运算符别名”:“Sequelize.Op”,“方言选项”:{“timezone”:“Asia/Tehran”},“timezone”:“Asia/Tehran”}```