Python Forum
Generate Multiple sql Files With csv inputs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate Multiple sql Files With csv inputs
#1
Hi Team,

I m new to python and started working on basics but cant get through when the problem goes to next level.

I have data looks like below and attached but I need to generate create statements out of CSV rows.

DB SCH TAB COL
DEV SCOTT EMP EMPNO
DEV SCOTT EMP ENAME
DEV SCOTT EMP DEPTNO
DEV SCOTT DEPT DEPTNO
DEV SCOTT DEPT DNAME
DEV SCOTT DEPT LOC

I want to generate 1 file for each table

CREATE VIEW SCOTT.EMP_V
AS
SELECT
EMPNO,
ENAME,
DEPTNO
FROM
SCOTT.EMP; --> This output is routed to EMP_V.sql file

CREATE VIEW SCOTT.DEPT_V
AS
SELECT
DEPTNO,
DNAME,
LOC
FROM
SCOTT.DEPT; --> This output is routed to DEPT_V.sql file

I am browsing through list and dictionaries and trying to do in parallel.

df = pd.read_csv("view.csv")
print(df)
df1=df.groupby(['DB','TAB'])['COL'].apply(','.join)
print(df1)
df2 = df1.reset_index(name = 'COLS')
print(df2)

Any better inputs are appreciated.
Please let me know

Attached Files

.csv   view.csv (Size: 143 bytes / Downloads: 325)
Reply


Messages In This Thread
Generate Multiple sql Files With csv inputs - by vkomarag - Aug-19-2021, 01:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to generating multiple json files using python script dzgn989 4 2,422 May-10-2024, 03:09 PM
Last Post: deanhystad
  python convert multiple files to multiple lists MCL169 6 3,371 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  Multiple variable inputs when only one is called for ChrisDall 2 1,275 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  splitting file into multiple files by searching for string AlphaInc 2 2,922 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 3,269 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 1,649 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Find duplicate files in multiple directories Pavel_47 9 7,205 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  Extract parts of multiple log-files and put it in a dataframe hasiro 4 3,777 Apr-27-2022, 12:44 PM
Last Post: hasiro
  Search multiple CSV files for a string or strings cubangt 7 13,365 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  Rename part of filename in multiple files atomxkai 7 10,964 Feb-18-2022, 10:03 PM
Last Post: atomxkai

Forum Jump:

User Panel Messages

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