How can I re-write column names when reading from an Excel file? #242
Unanswered
tboddyspargo
asked this question in
Q&A
Replies: 1 comment
-
No, this is not possible in the underlying GDAL driver. But you could provide your own column names by simply aliasing the table expression: SELECT * FROM st_read('./google_sheets.xlsx', max_batch_size = 100)
AS my_table(custom_name1,custom_name2,custom_name3);
┌──────────────┬──────────────┬──────────────┐
│ custom_name1 │ custom_name2 │ custom_name3 │
│ double │ varchar │ varchar │
├──────────────┼──────────────┼──────────────┤
│ 123.0 │ 500,60 │ ABC │
│ 456.0 │ 300,40 │ some text │
└──────────────┴──────────────┴──────────────┘ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We would like to be able to apply some "column name normalization" logic to the headers in an Excel sheet that are quite similar to the logic applied by
read_csv_auto
(e.g. spaces become underscores). However, I'm not sure thatst_read
or GDAL provide any options for achieving this.With CSV files, I can do:
SELECT * FROM read_csv_auto('s3://bucket/path.csv', names=['custom_name1', 'custom_name2'])
to set my own column names to use. Without that, the columns names would also be normalized according toread_csv_auto
's own logic (which I like).However, with
SELECT * FROM st_read('s3://bucket/path.xlsx', layer='sheet 1', open_options=['HEADERS=force'])
, no normalization logic is applied and I don't see an obvious way for me to provide my own custom column names.Any suggestions for how to enforce some column name normalization logic would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions