如何使用 POSTGRESQL 将 select 放入整数中

How to put a select into an integer with POSTGRESQL

我想把这个请求(SELECT qte FROM table_stock where id_pro = cpt1)变成一个整数,这样我就可以检查产品是否仍然存在(如果数量>0)所以我使用

SELECT qte 
   into quantite 
FROM table_stock 
where id_pro = cpt1;

PL/pgSQL reference

中有更多详细信息

尽量避免使用单个查询的循环,例如 insert into table_result select... where quantity > 0;