Informix 7.3 - 声明日期列数据类型,默认为插入/更新时的当前日期
再次寻求您的帮助Jonathan Leffler!
我正在 Informix 7.3 上创建一个表,并且需要一个时间戳字段,该字段在插入和更新时默认为今天
。
如何为具有当前时间默认值的表定义日期/日期时间/时间戳列?
以下是简单日期字段的字段定义:
column upd_date date
comments ""
desc "Last update date"
heading "Last update date"
text "Last update date"
attributes
(
)
架构文件中还有一些其他语法,其中包含有关默认应该的注释:
column beg_date date{DEF: date academic session/subsession officially begins}
comments ""
desc "Beginning date."
heading "Beg Date"
text "Date - Begin"
attributes
(
)
我不确定是否有任何其他表具有此功能,我什至不能 100% 确定它是否受支持,但如果有办法,我很想知道。
我在该主题上找到的唯一好的线索是 此处< /a>
有人有任何想法/解决方案吗?
More findings:
http://www.4js.com/techdocs/genero/fgl/devel/DocRoot/User/DatabaseSchema.html
Cast Date in Informix
我在另一个表定义中找到了一个 datetime
列类型:
column beg_time datetime year to minute
comments ""
desc "Beginning date and time of period"
heading "Beg Time"
text "Date/Time - Slot Begin"
attributes
(
)
{DEF: date and time this group/person may register}
Looking for your help again Jonathan Leffler!
I am creating a table on Informix 7.3 and need a timestamp field that will default to today
on inserts and updates.
How can I define a date/datetime/timestamp column for a table with a default value of the current time?
Here is a field definition for a simple date field:
column upd_date date
comments ""
desc "Last update date"
heading "Last update date"
text "Last update date"
attributes
(
)
There is also some other syntax in schema files that have comments about what the default should be:
column beg_date date{DEF: date academic session/subsession officially begins}
comments ""
desc "Beginning date."
heading "Beg Date"
text "Date - Begin"
attributes
(
)
I'm not sure of any other tables that have this functionality, and I'm not even 100% sure that it is supported, but if there is a way, I'd love to know.
The only good lead I've found on the topic is here
Anyone have any ideas/solutions?
More findings:
http://www.4js.com/techdocs/genero/fgl/devel/DocRoot/User/DatabaseSchema.html
Cast Date in Informix
There is a datetime
column type that I found in another table def:
column beg_time datetime year to minute
comments ""
desc "Beginning date and time of period"
heading "Beg Time"
text "Date/Time - Slot Begin"
attributes
(
)
{DEF: date and time this group/person may register}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不认识问题中使用的元语言,所以我不确定它与 DBMS 的能力相比有什么能力。
这将为您提供一个表,如果您未在 INSERT 操作中指定,则将为其中的 4 个时间列中的每一个分配一个默认值:
另一方面,如果您指定了列,则指定的值优先。我假设 DBDATE="Y4MD-" 以便 DATE 值看起来像 DATETIME YEAR TO DAY 值:
这里,值全部指定,因此这些是存储的值。请注意,ISQL Perform 等程序(以及最典型的 I4GL 程序)将为所有列提供值,因此默认机制不会生效。
您可以使用触发器来更改 UPDATE 上的值,这样您就可以插入日期和“上次更新”列(以及 whodunnit 列 - 创建者和更新者 - 如果需要)。同样,您必须担心默认值与显式提供的值。
现在,由于您使用的是 IDS 7.3x(它最终在一两年前停止服务),因此您的功能与 IDS 11.70 中提供的功能略有不同。您应该考虑升级。
我(最终)找到了这段代码,用于在更新时使用触发器。它可以追溯到 2006 年。
玩得开心!
I don't recognize the meta-language used in the question, so I'm not sure what that is capable of compared with what the DBMS is capable of.
This gives you a table in which each of the 4 temporal columns will be assigned a default value if you don't specify it in the INSERT operation:
On the other hand, if you specify the columns, then the specified values take precedence. I'm assuming the DBDATE="Y4MD-" so that DATE values look like DATETIME YEAR TO DAY values:
Here, the values are all specified, so those are the values stored. Note that programs such as ISQL Perform (and most typical I4GL programs) will provide values for all the columns so the default mechanism won't take effect.
You can play with triggers to alter the values on UPDATE, so you can have a date inserted and a 'last updated' column (and whodunnit columns - created_by and updated_by - if you want). Again, you have to worry about defaults versus explicitly provided values.
Now, since you are using IDS 7.3x, which finally went out of service a year or two ago, you have slightly different functionality from what is available in IDS 11.70. You should be looking at upgrading.
I found this code (eventually) for playing with triggers on update. It dates from 2006.
Have fun!
注意:我从不在 DATE 或 DATETIME 列上使用WITHOUT NULL,因为在临时列上指定WITHOUT NULL 时,最好有一个不存在的值,而不是1899 年12 月31 日。
NOTE: I never use WITHOUT NULL on a DATE or DATETIME column since it's better to have an absent value as opposed to 12/31/1899 when WITHOUT NULL is specified on a temporal column.
这是经过测试的&适合我 - 仅适用于插入。我假设如果您需要字段在每次更新时更新到当前日期,您可以使用触发器处理更新场景
This is tested & works for me - ONLY FOR INSERTS. I assume that you can handle the update scenario with a trigger if you need the field to update to the current date on every update