I've been reading this insert statement for two days and cannot identify which extra value is being added to the insert query.The amount of columns in the table and number of columns specified in the insert query are correct so can someone please show me which extra value is being added
I'm using a python script with dictionaries to create both the create and insert statements.PostgreSQL is used for the database.
The string created by python for Create
CREATE TABLE IF NOT EXISTS AiSTestTable(newID text not null constraint AiSTestTable_pkey primary key,aismessagesourceid int,messagechecksum text,offset0 text,utcmonth int,aismessagerepeatind int,utcyear int,latitude2s float,increment0 text,timeout0 text,aismessageid int,positionaccuracy int,latitude int,communicationstate int,utcminute int,positionfixingdevice int,utcday int,messagedatestamp timestamp,spare int,messagerssi
float,utchour int,datafile text,messagefreq float,messagechecksumresult text,messagedecoded text,longitude2s float,longitude int,utcsecond int,messagelength int,transmissioncontrol int,aismessageidtext text,raimflag int,numberofslots0 text); ALTER table AiSTestTable OWNER to postgres;
The string created by python for Insert
INSERT INTO aistesttable (newID,aismessagesourceid,messagechecksum,offset0,utcmonth,aismessagerepeatind,longitude,latitude2s,increment0,timeout0,aismessageid,positionaccuracy,latitude,communicationstate,utcminute,positionfixingdevice,utcday,messagedatestamp,spare,messagerssi,utchour,datafile,messagefreq,messagechecksumresult,messagedecoded,longitude2s,utcyear,utcsecond,messagelength,transmissioncontrol,aismessageidtext,numberofslots0,raimflag) VALUES ('1','113669999','59','0000','0','0','5834147','45.72','0000','0000','4','1','27432000','0','60','1','0','2018-07-30 09:13:37 UTC','0000','0','-48.0772018433','24','Broker','161.975344','Fail','yes','9.72357833333','0','60','37','0','Basestation report','0000','0');
This is the code to create the strings(newID is a count value)
TagString = str(d1.keys()).replace("['","").replace("']","").replace("', '",",")
TagType = str(d2).replace("': ["," ").replace("], '",",").replace("{'","").replace("}","").replace("'","").replace("]","").replace('"','').replace("[","")
newID="'"+str(c)+"'"+","
values=str(d1.values()).replace("[[","").replace("[","").replace("]","").replace(", '",",'")
commands = "CREATE TABLE IF NOT EXISTS AiSTestTable" + "(newID text not null constraint AiSTestTable_pkey primary key,"+TagType+"); ALTER table AiSTestTable OWNER to postgres;"
insert = "INSERT INTO aistesttable (newID,"+TagString+")" + " VALUES " + "("+newID+values+");"
Values in dictionaries
d1={'aismessagesourceid': ['113669999'], 'messagechecksum': ['59'], 'offset0': ['0000'], 'utcmonth': ['0'], 'aismessagerepeatind': ['0'], 'longitude': ['5834147'], 'latitude2s': ['45.72'], 'increment0': ['0000'], 'timeout0': ['0000'], 'aismessageid': ['4'], 'positionaccuracy': ['1'], 'latitude': ['27432000'], 'communicationstate': ['0'], 'utcminute': ['60'], 'positionfixingdevice': ['1'], 'utcday': ['0'], 'messagedatestamp': ['2018-07-30 09:13:37 UTC'], 'spare': ['0000', '0'], 'messagerssi': ['-48.0772018433'], 'utchour': ['24'], 'datafile': ['Broker'], 'messagefreq': ['161.975344'], 'messagechecksumresult': ['Fail'], 'messagedecoded': ['yes'], 'longitude2s': ['9.72357833333'], 'utcyear': ['0'], 'utcsecond': ['60'], 'messagelength': ['37'], 'transmissioncontrol': ['0'], 'aismessageidtext': ['Basestation report'], 'numberofslots0': ['0000'], 'raimflag': ['0']}
d2={'aismessagesourceid': ["'int'"], 'messagechecksum': ['text'], 'offset0': ['text'], 'utcmonth': ["'int'"],
'aismessagerepeatind': ["'int'"], 'utcyear': ["'int'"], 'latitude2s': ["'float'"], 'increment0': ['text'],
'timeout0': ['text'], 'aismessageid': ["'int'"], 'positionaccuracy': ["'int'"], 'latitude': ["'int'"], 'communicationstate': ["'int'"], 'utcminute': ["'int'"], 'positionfixingdevice': ["'int'"], 'utcday': ["'int'"], 'messagedatestamp': ['timestamp'], 'spare': ["'int'"], 'messagerssi': ["'float'"], 'utchour': ["'int'"],
'datafile': ['text'], 'messagefreq': ["'float'"], 'messagechecksumresult': ['text'], 'messagedecoded': ['text'], 'longitude2s': ["'float'"], 'longitude': ["'int'"], 'utcsecond': ["'int'"], 'messagelength': ["'int'"], 'transmissioncontrol': ["'int'"], 'aismessageidtext': ['text'], 'raimflag': ["'int'"], 'numberofslots0': ['text']}
