Skip to content

Instantly share code, notes, and snippets.

@tsnoad
Created October 7, 2010 06:44
Show Gist options
  • Save tsnoad/614667 to your computer and use it in GitHub Desktop.
Save tsnoad/614667 to your computer and use it in GitHub Desktop.
insert days into a psql database
#!/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