How to add a Time dependent trigger in PostgreSQL? - postgresql

I'm confused and clueless on how to:
Add a trigger to a postgresql db once the db has been set up, i.e. adding a trigger by clicking a hyperlink
Write a trigger function so that it deletes a specific row after a week has passed since the trigger was written.
This is the sequence once events just for clarity
Admin sees entry in db via a php generated html page.
Admin clicks 'approve' hyperlink next to db entry.
This creates a trigger in the db to delete that specific row after 1 week has passed.
I need help with step 3
Would an alternative way of doing this be to have a trigger on the table, so that when a row is inserted a new trigger is created which checks the value of an 'approved' column for that row. When the Admin clicks 'approve' in the html page the word 'yes' is inserted to the 'approved' column for that row. The trigger will detect this and add a new trigger to delete the row after a week?
As you can tell i'm really not sure which way to do it and how to do it so any feedback would be much appreciated. Thanks.

Simple: Store an expiration date for the url in your db, only retrieve currently valid records (you can use a view for this) in your select, and delete expired urls from time to time.
You can't use a trigger though. pgAgent or cron could be used to start a cleanup process though.

Related

how to use datediff properly tableau

basically i have the same problem with this and use this solution too https://community.tableau.com/s/question/0D54T00000C6aS6/datediff-in-lod
so i want to count time diff between transaction for each transaction and for each users, basically my problem is just like this
same with that, ON interaction id = user id in my real data, so i want to know time different between date transaction for each users.
based on that, i made this on calculation DATEDIFF('day',LOOKUP(MIN([Created At]),-1), MIN([Created At]))
and here's the results
what makes me confuse is, why the first transaction of users always have time difference, instead it must be nothing because there's no time difference if you do first transaction, so how to make it not appear?
Create a table calc field for First
FIRST()=0
Edit the table calc so it resets ever new user id.
Now filter for False. You can remove it from Rows, I just kept it there for demo. Your calculation will still work.

MS Access: Make Form show only records from last 48HS

I am using MS Access and I have a table called tblLogs, it contains all the logs and a field called logDate. I have created a form in which I need to show the data from tblLogs, but only the records from the last two days. My question is: what are my options?
I've been doing some research and tried making a query which retrieves the data I need from last 2 days, but after doing it I realized there wasn't an easy way to bind query content to a Control (a text box in this case). Another option that came to mind was somehow setting an automatic filter that is triggered when you open the form (don't know how to do it yet), but I don't know if that would be convenient.
So, I'm all ears guys
In the form properties set Filter On Load to Yes and Filter to
logDate >= DateAdd('h', -48, Now())

User opens one screen in two browser tabs and press update button within milliseconds

I am running into one issue. Any help would be appreciated.
I am using PostgreSQL as back end.
The issue is: User opens one screen in two tabs and press update button within a second.
Example - table fields - id - is_posted
I have a flag on the table which I am setting it to true - is_posted = true and after setting this flag to true I have a trigger which inserts few records in other tables. If is_posted = true then I am not allowing the user to update that record again.
If a user clicks 'Update' button in one tab and after 1 - 2 seconds clicks 'Update' button on other tab then I get updated value and easily throw validation message that "Record already updated".
But if a user follows the same process but within milliseconds, then I do not get the updated data and record get updated twice. And it is creating multiple records in other tables which is leading to create bad data.
Kindly suggest.
Thanks,

Copying records from one table and to another based on the value of a yes/no field

I'm beginner in MS Access and I have managed to make my own database for customers who sign up for soccer academy. Now what I want to learn is how to make a macro to do the following action:
"If a Yes/No field in Table1 is equal to 'Yes' then copy the record from Table1 and paste it to Table2"
I signed up a lot of new players because I gave them 1st day free and not all of them continue after that. What I want from this system is if that new player pays, I want him in a separate table to further calculate financial stuff.
I have made a form to sign up players and two tables, one for newly registered and one for those who continue with us and paid.
What you're going to want to do is create an Append query. You can do this by following these steps:
Click on Create, then Query Design from the ribbon on top
Select Table1 from the Show Table popup, and click "Add"
Click "Close" from the Show Table popup
Highlight all your fields, then click-n-drag them into the grid at the bottom
In your Yes/No field, set the Criteria to Yes
Click "Design" from the ribbon on top and choose Append
Set the Append To Table Name to be Table2
Save the query
Then, just set up a macro to run the query you've just created.
Without specific information, that's the best I can do. But it's definitely the easiest way to go. You can write VBA to do it, but that requires a bit more knowledge

Filemaker Pro 11 Script - Add fields dynamically?

So we use FMP11 to do inventory management. I do price updates to our products 3 times a week and it would be nice to store our past cost values into a separate table for historical pricing. I know how I would go about doing most of it, but is it possible to create a new field that is labeled as today's date on the fly? So my headers would be labeled with that days date and the old pricing value from my other fields would be inserted.
It is a bad idea to create new fields for the purpose you're describing. Create additional records instead, and do your report going from top to bottom instead of left to right.
That said, if you want to do it, you can using FileMaker Server Advanced with JDBC and the ALTER TABLE command.
Create an new table (e.g. ArchivePricing) to hold the values you want to reference at a later date (e.g. ChangeDate, Price, Item, ItemID, etc.).
Create a new field in the current table called z|newprice - use this to type in your new pricing (you might do this on a list layout so you can easily change a bunch of prices).
Create a button that triggers a script that:
creates a new record in the new ArchivePricing table and inserts the ItemID (thus creating a link to the original table) - this can be done using script parameters or setting a variable)... the script continues.
uses the "set field" script step to insert info to this new record in the ArchivePricing table.
uses the Get (CurrentDate) function to insert the date into the ChangeDate field (thus capturing the date the change was made).
Before the script finishes be sure to use "set field" back in the original table to move the value in z|newprice field into your normal Price field. Do this at the end of the script and then commit record.