Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSTGRESQL,subquery in FROM must have an alias

Tags:

postgresql

CREATE OR REPLACE FUNCTION sp_insert_nike_mapping_code ( shopId bigint ) RETURNS VOID AS $body$
BEGIN

    insert into temp_t_so_sales_order_push(so_code,seq)
   SELECT so_code,nextval('s_t_so_sales_order_push_code') from (
   SELECT so_code from t_so_sales_order_push where sync_status = 0 group by so_code
   );

   update t_so_sales_order_push pu
   set code = (
       SELECT temp.seq from temp_t_so_sales_order_push temp
       where temp.so_code = pu.so_code and pu.shop_id = shopId and pu.sync_status = 0
   )
   where exists(
          SELECT 1 from temp_t_so_sales_order_push temp
          where temp.so_code = pu.so_code and pu.shop_id = shopId and pu.sync_status = 0
   );
END
$body$
LANGUAGE PLPGSQL
SECURITY DEFINER
;

when I executed the above code,got the syntax error: subquery in FROM must have an alias. [Err] ERROR: subquery in FROM must have an alias LINE 5: ...ELECT so_code,nextval('s_t_so_sales_order_push_code') from ( ^ HINT: For example, FROM (SELECT ...) [AS] foo.

Does anyone help me?

like image 985
Carlos Zhang Avatar asked Oct 17 '25 03:10

Carlos Zhang


1 Answers

insert into temp_t_so_sales_order_push(so_code,seq)
   SELECT t.so_code,nextval('s_t_so_sales_order_push_code') from (
   SELECT so_code from t_so_sales_order_push where sync_status = 0 group by so_code
   ) as t;
like image 91
lat long Avatar answered Oct 19 '25 18:10

lat long



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!