sql - Update related table (Postgres) -
i creating 2 table in postgres.
1st table have 1 primary column , other columns & in 2nd table have 1 primary column "mleaseid" column same in 1st table (not primary of 1st table) , others column.
how copy data 1st table column second column data?
create table leasetype ( "leasetypeid" integer not null , "mleaseid" character varying(45) not null, "resident" integer not null, "business" integer not null, "rarea" float null, "barea" float null, "rrent" double null, "brent" double null, primary key (leasetypeid) ); create table masterlease ( "srno" integer unsigned not null, "mleaseid" varchar(45) not null, "extid" integer unsigned not null, "mplotno" character varying(45) not null, "dplotno" character varying(45) not null, "sheetno" character varying(45) not null, "nastino" character varying(45) not null, "date" date not null, "lholdername" character varying(45) not null, "phoneno" character varying(45) default null, "totarea" double not null, "leaseduration" float not null, "usetypeid" int(6) not null, "lfromdate" date not null, "ltodate" date not null, "orderdtl" text, "remark" text, "address" character varying(300) not null, primary key (mleaseid) )
you can insert data selecting other tables (by query @ all, you'll have make sure data being returned query same of insert parameters. if understand correctly want line being added masterlease, have "mleaseid" column mix of various leasetype columns.
try this:
insert masterlease( "srno", "mleaseid" ) select 123, concat(leasetype."mleaseid",'any_code', leasetype."rarea")::varchar mleaseid leasetype
of course need add other values well. can manually did in "srno" or can join other tables in select statement.
don't forget columns type of insert statement must match select statement. can enforce casting (::varchar example).
Comments
Post a Comment