一个SQL查询中的两种不同操作

时间:2019-04-18 07:01:03

标签: postgresql

我有两个sql查询。 第一个是插入:

insert into categories  (id, title,kind,parent_id,sort,url)  values (DEFAULT, 'test21','РАБОЧИЕ КАТЕГОРИИ','721','0', 'test21');

第二个是更新:

with
t1 as (select id as _id, parent_id, url as url1, title as title1 from categories where parent_id !=0),
t2 as (select id, url as url2, title as title2 from categories where parent_id =0),
t3 as(select * from t2 INNER JOIN t1 ON (t2.id= t1.parent_id)),
t4 as(select _id, '/'||url2||'/'|| url1 as new_full_url, '/'||title2||'/'|| title1 as new_full_bc from t3),
t5 as (select _id, new_full_url, new_full_bc from t4 union select id, url2, title2 from t2)
update categories set full_bc=new_full_bc, full_url=new_full_url from t5 where categories.id=t5._id;

它们可以很好地用作两个单独的查询。但是由于某种原因,我需要将这些查询连接到一个查询中,这两个查询就像一个查询。有可能吗?

我的意思是这些查询是顺序执行的。第一个,然后第二个。我需要这些查询像一个查询一样执行,或者正如我所说,这两个查询就像一个查询一样。

1 个答案:

答案 0 :(得分:2)

无需进一步检查您的查询(请将其最小化,以便我们进行检查)。将$ cat a.js var array1 = [{"name":"a","value":"foo"},{"name":"b","value":"bar"},{"name":"c","value":"boo"},{"name":"d","value":"far"}] array1.forEach(function(element) { Object.keys(element).forEach(function(key) { console.log(key); console.log(element[key]); }); }); $ node a.js name a value foo name b value bar name c value boo name d value far 语句放入public class DeviceFileStatusDM { [ExplicitKey] public Guid ID { get; set; } public Guid DeviceID { get; set; } } 子句对您有用吗?

INSERT