How to Create Date Incrementing Trigger in Postgresql - postgresql

I'm not very experienced in Postgresql, and in a personal project I have the table column ID (Primary Key) being a date with format yyyy-mm-dd, like this
ID
---
2020-07-12
2020-07-13
2020-07-14
I want to create a trigger so that ID value gets automatically incremented (based on latest ID value) when a new record is inserted. Also what is the recommended data type for the column ID in this case?
My goal
The table stores Daily Report summaries, it's already known that new record will be the next day and I want to eliminate the need to specify the report's Date manually.
Report data is inserted using service call to application, and reducing the payload params to the minimum is important.

Related

I have problem in getting data perfectly in adf

Cconsider one CSV file with employee details and attendance marking attendance with 0 and 1. For example, 1 indicates the employee is present, 0 indicates employee is absent. My problem is to get the working date of employee if they are present (1). It should be the same day where the employee is absent (0). It should be next working day by reading the previous row.
emp id
working
working day
123
1
11/14/2022
123
0
11/15/2022
123
1
11/14/2022
I have tried using data flow in ADF, but it is not getting. Please provide solution for me in Azure Data Factory.
To manipulate the csv data in data factory we have to use Data Flow activity in Azure data factory
I reproduce your scenario in my environment please follow below steps to get issue resolved:
I took one sample file as source in Data flow activity similar to data you provided as below (assuming you don't have date values when employee is absent):
Then I took windows transformation activity over emp id and sort by emp id and created windows column working date with updating Date based on previous row value with expression:
lag(addDays({working day}, 1),1)
Windows transformation data preview:
Now I took derived column transformation to get date working date of employee if they are present or absent. I am updating the column working day if working is 0 then value should be working date else value will working day.
iif(working==0,{working date},{working day})
Derived column transformation data preview:
Now with select activity delete unnecessary columns and store the data in sink.
Select transformation data preview:

SSAS Tabular - No relation between fact table and 2nd Date dimension

I have 2 date fields in my fact table start_date and end_date.
Fact table is connected to the dim date with start_date.
I need to slice data by the second date field so I've created another date dimension similar to the first dim date and connected the key to the end_date in the fact table, but for some reason there's no relation between them when I browse the cube.
I made sure the keys are in the same format, data type etc.
The new dim date is 'marked as date table'.
What am I missing?
Thanks a lot.
Try with TabularEditor:
https://github.com/otykier/TabularEditor/releases/tag/2.13.0
open your Model and check relationships if you don't see the one you want, you can just add a new one.
You can also create multiple relationships to the same table using different columns (but as inactive), you can use this inactive relationship in calculation using USERELATIONSHIP.

ms access autofill date field based on date of previous record

I have a table that has estimate numbers for each department on a given date (each date is a record with fields EST_DATE, DEPT1, DEPT2, DEPT3, etc.). The date is the indexed primary key (no duplicates).
When a user creates a new record I would like the date to autofill based on the last record.
So if the last estimate was for 07/02/2015, the date for the new record should autofill as 07/03/2015. Using a default value based on the current date won't work because these estimates are generated days or weeks in advance. If it matters, the format for field EST_DATE is set to "mm/dd/yyyy".
I would prefer to use the default value of the EST_DATE field itself, but I can also use event-based VBA since users will normally be entering this estimate data via a bound form.
Create a hidden textbox named, say, MaxEstDate.
Set it's ControlSource to: =Max([EST_DATE]).
Set the DefaultValue of the textbox with EST_DATE to: =[MaxEstDate].

Want to get the MAX(ID) from a db table datewise, but it returns only same ID in sqlserver 2008 r2

I am trying to get the maximum ID from a database table and want to show it on win form load.
I am using the following query to get the maximum ID.
SELECT ISNULL(MAX(ID),0)+1 FROM StockMain WHERE VRDATE = '2013-01-30'
Above should have to return the maximum ID of today., e.g if I this statement is excutes for the first time it will return me the Value '1'. After saving first record on ID = '1' it should give me MAX(ID) = '2'. But it returns me the value 1.
Any suggestion or solutions????
Wild guess... but what data type is VRDATE? Does it include a time component, or is it just a date?
If it includes a time component indicating when you saved the record, it won't pass the VRDATE = '2013-01-30' check, since this defaults to a time of midnight. Since the times aren't identical, they are not equal.
Instead, try:
SELECT ISNULL(MAX(ID),0)+1
FROM StockMain
WHERE VRDATE BETWEEN '2013-01-30' AND '2013-02-01'
Next question... have you considered using an IDENTITY column instead of managing the ID values manually?

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.