I am writing an sql script in informix that loads data from a csv file into a temporary table, and then will insert data if it doesn't already exist.
The csv has 3 columns and is inserted into a temp table called temp_table_csv:
temp_table_csv
msg_group
code
message
'code' corresponds to the same code field in table1 and table1.ID is a foreign key to table.code_id.
table1
ID serial PK
code varchar(255) FK
msg_group varchar(255)
table2
lang_id serial PK
code_id varchar(255) FK
msg_pt1 varchar(255)
msg_pt2 varchar(255)
If the code in the temporary table exists in table1, then I want to ignore it.
Otherwise, if it does not exist:
A new entry in table1 should be added with a new ID and the msg_group from the temp table. Also table2 should be updated with the code_id being the table1.ID and msg_pt1 being the message.
I have got the data into the temp table and i'm not sure how I can check to see if the 'ID' exists now.
table2have anIDcolumn too? If not, how aremsg_pt1andmsg_pt2associated with theIDin the database? Iftable2has anIDcolumn, is there a foreign key relationship betweentable1andtable2such that if a row appears intable2, it must also appear intable1? Can rows appear intable1without having an entry intable2? Are there any other columns intable1? Which version of Informix are you using? And on which platform (o/s and version)? Do you have the MERGE statement available? - Jonathan Lefflertable1.IDandtable2.code_IDare different (SERIAL vs VARCHAR), it is hard to see how you maketable2.code_IDinto a foreign key referencingtable1.ID. - Jonathan Leffler