posts icon indicating copy to clipboard operation
posts copied to clipboard

`%sqlcmd columns` outputs sql.inspect.Columns

Open prakashperiasamy opened this issue 1 year ago • 0 comments

Hi Objective: Using the %sqlcmd columns I like to access the column names (as a dataframe or series or list) of tables in a database.

What I did: Cell#1: %sql USE DATABASE {DB Name} %sqlcmd columns --table {Table Name} --schema {Schema Name}

Cell#2: (to capture the previous result) df = _ Cell#3: (to know the data type of the result) type(df) output: sql.inspect.Columns

Hence I'm not able to apply any methods or functions to convert this into a dataframe or series or list.

Q1: Is there a way I can access the output as a dataframe instead of sql.inspect.Columns Q2: Is there a way to consolidate cell#1 & 2. Is there a way to directly store the output of %sqlcmd into a variable directly.

prakashperiasamy avatar May 03 '23 22:05 prakashperiasamy