sqldeepnote

How do I rename a column in Dataframe SQL?


"RuntimeError: Catalog Error: Can only modify view with ALTER VIEW statement" When trying to rename a column while using DataFrame SQL within Deepnote

ALTER TABLE df RENAME COLUMN V41690973 TO cpi;

A screenshot giving some more context enter image description here


Solution

  • You can use the SELECT * EXCLUDE (col_name) syntax in combination with Deepnote's ability to overwrite the variable df from Dataframe SQL to rename a column like this:

    SELECT
        col1 as col1_renamed,
        * EXCLUDE (col1)
    FROM df
    

    enter image description here

    Here's a published reproducible notebook: https://deepnote.com/@the21st/Rename-a-column-using-DataFrame-SQL-1864ef27-a977-4039-bdc5-3b81215a2f2e in case you want to fork it and try it yourself.