ThinkGeo.com    |     Documentation    |     Premium Support

How to add a column to PostgreSQL layer and update the column

Hi,


I have a PostgreSQL feature layer,  I want to add a column then update it later one by one.


How to do this?


Thanks


Rose


 



Rose, 
  
 We don’t directly support adding Columns to Postgre FeatureSource, I think you can use ExecuteNonQuery() method and add the new column with SQL, something like 
  
 
postgreFeatureSource.ExecuteNonQuery(“ALTER TABLE mytable ADD COLUMN newcolumn text;”);
 
  
 Thanks, 
  
 Ben

Posted By Ben on 05-10-2009 09:58 PM 

Rose, 



We don’t directly support adding Columns to Postgre FeatureSource, I think you can use ExecuteNonQuery() method and add the new column with SQL, something like 






postgreFeatureSource.ExecuteNonQuery(“ALTER TABLE mytable ADD COLUMN newcolumn text;”);






Thanks, 



Ben 

Ben, thanks for your time.


If I use Postgre FeatueSource to add the new columns with the SQL string,that will add the columns to the linked background database table, so the table structure will be changed.  That is not what I want. Also my PostgreFeature layer is linked to a view instead of a table.


I wanted to add  temp columns to store the calculation results, and also use these temp columns in SQL squery, so at the end I can export the Postgre Feature layer  which contains the temp columns to an ESRI shape file.


Is this possible?


Thanks



 



Rose, 
  
 We can add a temp column using the CustomColumnFetch event, but the temp column added this way will not support SQL query. So I think maybe a better way is: in the method ExecuteNonQuery(), create another View with that temp Column Added , connect to this new View and then you can either execute any SQL query, or export it to a shape file.  
  
 Here is the SQL how to created a View with the TempColumn added. 
  
 CREATE VIEW New_View 
 AS SELECT ColumnA, ColumnB, TempColumn=’’ 
 FROM MyTable 
  
 Let me know for any queries. 
  
 Thanks, 
  
 Ben