Python Forum
Approach to creating Audit table
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Approach to creating Audit table
#5
Here's my attempt at explanation and again i am very very new to Python :

Assignment : Read the csv files and load the data into tables in postgres database.

Code for reading and loading the files into postgres tables is working.(utilized pandas , numpy , sqlalchemy )

Requirement : Need to account whether the script ran fine and all tables got loaded.

One approach that i had was to come up with an Audit table that has name of the table ,load_status and load_date.


there are 12 tables. If the count is greater than 0 for each table , meaning table got loaded with records.



conn = create_engine ("postgresql://<id>:<password>@hostname:port/databasename")
   cur = conn.cursor() #to execute select statements
   cur.execute (""" CREATE TABLE Audit ( table_name text , Load_status text , load_date date)""")
   cur.execute("Select * from table1")
   results_table1 = cursor.fetchall()
   for r in results_table1:
     if results_table1 > 0:                 [b][i]## I am not sure how to achieve it.[/i][/b]
        then INSERT_QUERY = { "INSERT INTO Audit VALUES {}".format("(table1name" ,'Successful' ,'02-24-2020')")
        cur.execute(INSERT_QUERY)
## also i have to check it for all 12 tables

I am not sure whether this is correct approach
Also any other suggestions to achieve the requirement stated above is appreciated.

Thanks !
Reply


Messages In This Thread
Approach to creating Audit table - by pynewbie - Feb-21-2020, 07:09 PM
RE: Approach to creating Audit table - by pynewbie - Feb-21-2020, 08:14 PM
RE: Approach to creating Audit table - by micseydel - Feb-23-2020, 11:42 PM
RE: Approach to creating Audit table - by pynewbie - Feb-24-2020, 06:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Advice needed on how to approach this problem... sawtooth500 1 297 Apr-06-2024, 01:55 PM
Last Post: snippsat
  Sound Approach for Running a Shell Command? matt_the_hall 8 3,413 Dec-14-2020, 02:52 PM
Last Post: matt_the_hall
  Need feedback on my approach for python dashboard for Asana pashtett 0 1,345 Nov-24-2020, 11:51 AM
Last Post: pashtett
  Creating table in MySQL db with decimal number issue dangermaus33 7 4,963 Nov-20-2020, 10:40 PM
Last Post: dangermaus33
  Creating a table in SQLite3 djwilson0495 2 2,085 Aug-10-2020, 03:01 PM
Last Post: djwilson0495
  list approach due nested order 3Pinter 6 2,880 Oct-07-2019, 01:49 PM
Last Post: 3Pinter
  Whats a good design/approach? hshivaraj 1 1,796 Sep-16-2019, 01:44 AM
Last Post: snippsat
  Creating a delimited file from DB Table anubhav2020 9 7,186 Sep-19-2018, 05:22 PM
Last Post: Axel_Erfurt
  Recommendation after running regression (approach) danishzmalik 0 1,662 Jul-17-2018, 09:31 AM
Last Post: danishzmalik
  Table creating code qqqqqqqqqqqq 1 2,488 Jun-18-2018, 11:15 AM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020