Python Forum
Approach to creating Audit table
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Approach to creating Audit table
#1
I am very very new to Python and the problem i have might be very easy for python pro's.

I am working on an assignment in which there is a part which is :

Create an Audit table in which row is inserted when all the tables are loaded with timestamp.



import pandas as pd
df = pd.DataFrame(data,columns=['Load Status','Updated Timestamp'])
. -- Creating data frame to apply logic


df_.to_sql("Audit Table ", conn, if_exists="replace", index=False) -- creating table into database.

Not sure how to tackle it or what is the right approach to achieve it.
Reply
#2
This is homework, as such, it is best for you to make your best effort THEN post asking questions about what you are having trouble with.
Reply
#3
Thanks for replying.

It would have been easy for me to tackle it in 'non-python' world. As i already mentioned , i am pretty new in this
and wanted to know the approach (not the solution).
Only reason i was prompted to this forum was to get some direction and it seems i am in wrong forum.
Reply
#4
(Feb-21-2020, 08:14 PM)pynewbie Wrote: Only reason i was prompted to this forum was to get some direction and it seems i am in wrong forum.
It's difficult to address vague questions. "Create an Audit table..." Perhaps you know what that means within the context of your course, but I don't. Does it require Pandas? What exactly is your assignment? We prefer code attempts to what I'm asking for here, and I'm not sure where your code falls into that, since I'm not clear on the requirements.
Reply
#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


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