Search code examples
postgresqlinsertpostgresql-9.3

populating values to a table from the same table based on condition and without condition


I have a table named 'plot' which has columns such as 'id','tablename','geom','description'. I need to populate the geom and description of the plot table from the same table itself based on specific condition.For ex select geom,description from plot where id=2;But need to populate other tow columns 'id', and 'tablename' with different values.Is that possible in postgresql?

sample_data


Solution

  • Sure, something like

    INSERT INTO plot (id, tablename, geom, description)
       SELECT 42, 'mytablename', p.geom, p.description
       FROM plot p
       WHERE id = 2;