csvsql: agate-sql: Add option to set varchar length to data's maximum length, or to a user-provided length
Author: StudentForeverCreated Jan 31, 2018Updated Jul 12, 2024
Labelsfeature: upstreamcsvsql
Hi
Not sure if I am not passing the right flags, I noticed that the column sizes in the create table query default to max e.g. varchar (max) . Is there an option so that column sizes are inferred based on the actual data.
cat test.csv
tag,tag2,Date,col1,col2,col3,col4,col5
DFAN8086,sss,12/24/2012,0.9454054,0.391277,0.696738598,0.963471,0.422531
FDG491BT1088,wew,12/24/2012,0.922601887,0.3125817,0.991514,0.740261,0.3096907
GEW00328745,tere,12/24/2012,0.341763918,0.587643,0.834997,0.611671,0.3686074
GWW02993182,qewqeqw,12/24/2012,0.078535992,0.497771,0.394849,0.4730659,0.4074645
csvsql -i mssql test.csv
CREATE TABLE test (
tag VARCHAR(max) NOT NULL,
tag2 VARCHAR(max) NOT NULL,
[Date] DATE NOT NULL,
col1 DECIMAL(38, 9) NOT NULL,
col2 DECIMAL(38, 7) NOT NULL,
col3 DECIMAL(38, 9) NOT NULL,
col4 DECIMAL(38, 7) NOT NULL,
col5 DECIMAL(38, 7) NOT NULL
);
Source: wireservice/csvkit