简体   繁体   English

根据特定日期更新Postgresql中的列

[英]Updating a column in postgresql based on a specific date

I'm wondering if I could use trigger with PostgrSQL to update a column where I do have column with date type and on this date I would like to updated another column in another table. 我想知道是否可以将触发器与PostgrSQL一起使用来更新我确实具有日期类型的列的列,并且在这个日期我想更新另一个表中的另一列。

To make it more clear 更清楚一点

I do have 2 tables 我有2张桌子

Works_locations table Works_locations表

walphid         wnumberid   locationid
DRAR            1012          101
PAPR            1013          105
PAHF            1014          105
ETAR            1007          102
DRWS            1007          102

the locationsid attribute refers to "locid' in Locations table which is down locationid属性是指位置表中的“ locid”

locid   locname     
101     Storage 
102     Gallary A   
103     Gallary B   
104     Gallary C   
105     Lobby   

Exhibition table 展览桌

exhid       exhname       description       strtdate        endDate
101         Famous         Blah Blah        2013-07-15      2013-10-13

and here are bridge table to connect the exhibition table with the locations table 这是连接展览桌和位置桌的桥桌

locationsid     exhibitid
102             102
103             101
104             103

Now Each exhibition has some works and should be placed in one of the locations table. 现在,每个展览都有一些作品,应该放在一个位置表中。

On the 'endDate' column in the exhibition table, which is a date data type, I would like to update 'locationid' column in the Works locations table to be placed in another location. 在展览表的“ endDate”列(这是一种日期数据类型)上,我想将“作品位置”表中的“ locationid”列更新为放置在另一个位置。

In another words. 换句话说。 Each exhibitions has some works and this works are placed in one of the locations. 每个展览都有一些作品,并且这些作品都放置在其中一个位置。 at the ending date of the exhibition, I would like to change the locations, and specifically, I would like the work to be returned to the storage. 在展览结束时,我想更改地点,特别是,我希望将作品退还给仓库。

Any idea how would I do this action with postgresql? 知道如何使用postgresql进行此操作吗?

Regard 看待

PostgreSQL does not have a built-in task scheduler. PostgreSQL没有内置的任务计划程序。 Even if there was a scheduler, the commands it ran wouldn't be triggers, they'd just be be procedures run by a scheduler. 即使有一个调度程序,它运行的命令也不会被触发,它们只是调度程序运行的过程。

You can't write triggers that fire at some arbitrary time. 您无法编写在任意时间触发的触发器。

You will need to use cron , Task Scheduler, PgAgent, or similar to run the statements at the desired time. 您将需要使用cron ,Task Scheduler,PgAgent或类似工具在所需时间运行语句。 Or you could write a script that checks when the next event is, sleeps until then, runs the desired command and marks that event as done, and sleeps until the next event. 或者,您可以编写一个脚本来检查下一个事件的发生时间,直到下一个事件休眠,然后运行所需的命令并将该事件标记为已完成,然后休眠直到下一个事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM