Skip to main content

Hi

I have some rows that need to be appended to a database table and some rows which need to be deleted then replaced

I am using a feature writer and  can delete rows by setting the feature operation to Delete and the in Row Selection, the Columns (Im sure it used to be called math columns) is just set to the primary key of the table. That way it appears to delete all the rows. I presume this is correct.

I then want to append the revised values to the table. How do I add another feature writer to do this?

I presume the alternative (better method?) is to use update. If I wanted to update every field, would I just set Columns in Row Selection just to the primary key and the all other columns would update? Would this still work if some of attributes are null?

Many thanks

 

 

 

 

You can use the same FeatureWriter to DELETE and INSERT. In the FeatureWriter, you can set the feature operation to ‘fme_db_operation’. On the features you want to delete, feed them into an AttributeCreator, creating an attribute called ‘fme_db_operation’ with a value of “DELETE”. Do the same with the features you want to insert, except make the value INSERT. Then feed both into the FeatureWriter. 

And you are correct about the Update. All attributes will be updated. It does sound like it would be the better solution in this case.


You can use the same FeatureWriter to DELETE and INSERT. In the FeatureWriter, you can set the feature operation to ‘fme_db_operation’. On the features you want to delete, feed them into an AttributeCreator, creating an attribute called ‘fme_db_operation’ with a value of “DELETE”. Do the same with the features you want to insert, except make the value INSERT. Then feed both into the FeatureWriter. 

And you are correct about the Update. All attributes will be updated. It does sound like it would be the better solution in this case.

Thanks you. If I delete and insert, it will be the same features, so unless I can guarantee the DELETE will happen first, Im not sure this will work.

UPDATE should be the ideal solution but I don’t really understand the way FME does this. If I only select the primary key in the Columns section, will it replace all other fields?

On another point, when I use the feature writer, I cannot browse to an existing table but have to type its name in. Is that correct?

 


 

Thanks you. If I delete and insert, it will be the same features, so unless I can guarantee the DELETE will happen first, Im not sure this will work.

You can try using a FeatureHolder to hold the INSERT features before executing the DELETE. If this is not helping, you can use two FeatureWriters in series, where the Summary of the first (DELETE) FeatureWriter kicks off the second (INSERT) FeatureWriter.

UPDATE should be the ideal solution but I don’t really understand the way FME does this. If I only select the primary key in the Columns section, will it replace all other fields?

E.g.: Your table contains columns ID, shape, data1, data2, data3, etc.. Your UPDATE features contain columns ID, data1, fme_db_operation. This way only your column data1 is updated, the rest will remain untouched.

You can also use a WHERE clause if you have other keys on which you would like to base your updates.
E.g.: in my SDE I have a column in which I define a certain state of my objects. I only want to update my most current objects so my WHERE clause is:

"status" = 0 AND @Value(ID)="ID"  

I also feel like filtering out my legacy objects before matching on column ID speeds up my writing process.

 

On another point, when I use the feature writer, I cannot browse to an existing table but have to type its name in. Is that correct?

This is correct. You provide a path to your database, and you enter the table name of your database you want to write to.

 

Hope this helps!


Reply