Created
October 7, 2010 06:44
-
-
Save tsnoad/614667 to your computer and use it in GitHub Desktop.
insert days into a psql database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#As reconcile.php runs, it adds entries to invoice, receipt, etc. tables. | |
#The timestamp fields in these tables reference the dw_timestamp table | |
#So, we need to add every conceivable date to dw_timestamp | |
#back to 1900 should be enough ^_^ | |
#set a variable to use as an iteration counter | |
export i=0; | |
#start at 1900-01-01 and add a day for each iteration | |
#keep on iterating as long as we haven't passed today | |
while [ `date +%s --date='1900-01-01 +'$i' day'` -lt `date +%s` ] ; do | |
#handy message to show progress | |
echo 'Inserting date '`date +%Y-%m-%d --date='1900-01-01 +'$i' day'`' into dw_timestamp'; | |
#run the SQL to do the insert | |
#target db should probably be abstracted | |
psql -c "INSERT INTO dw_timestamp (timestamp_id, complete) VALUES ('`date +%Y-%m-%d --date='1900-01-01 +'$i' day'`', 't');" ea_mart_financial | |
#increment the iteration counter | |
i=$(( i + 1 )); | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment