Link to home
Start Free TrialLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

the code run long time but it not delete table

the code below when I run it it not delete table but if i run

DROP TABLE IF EXISTS chg ;
then
I run

CREATE TABLE chg AS
SELECT sename."Date",
    sename.name,
    sename."Open",
    sename."Low",
    sename."Close",
    COALESCE(lag(sename."Open") OVER (PARTITION BY sename.name ORDER BY sename.name), sename."Close") AS lag_start
   
   FROM sename
  ORDER BY sename.name, sename."Date" DESC;

it work

DROP TABLE IF EXISTS chg ;

CREATE TABLE chg AS
SELECT sename."Date",
    sename.name,
    sename."Open",
    sename."Low",
    sename."Close",
    COALESCE(lag(sename."Open") OVER (PARTITION BY sename.name ORDER BY sename.name), sename."Close") AS lag_start
   
   FROM sename
  ORDER BY sename.name, sename."Date" DESC;


--- maxsec

DROP TABLE IF EXISTS maxsec ;

CREATE TABLE maxsec AS


  SELECT t."Date",
    t."Open",
    t.name,
    t."Low",
    t."Close",
    
    t.lag_start,
            ((t."Open" + t.lag_start) - ((2)::numeric * (t."Open" - h.value))) AS profit, 2 as mark,
    ROUND( ((((t."Open" + t.lag_start) - ((2)::numeric * (t."Open" - h.value))) * (100)::numeric) / t."Open") ,2)  AS perprofit,
    h.value
   FROM ("chg" t
   JOIN helpertable h ON ((((t."Open" - t."Low") - h.value) >= (0)::numeric)));

----


DROP TABLE IF EXISTS goodsec ;

CREATE TABLE goodsec AS


SELECT "maxsec".name,
    "maxsec".value,
    sum("maxsec".perprofit) AS profit100,
    count("maxsec".value) AS countva
   FROM "maxsec"
  GROUP BY "maxsec".name, "maxsec".value;

Open in new window

Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

With what tool are you running it?
Avatar of MrTV

ASKER

navicat
You seem to be saying they fail when run together in a single query window. How about if you just run the first drop and create query, rather than all 3 pairs of queries?
Avatar of MrTV

ASKER

Hi TerryAtOpus

work
Ok, so how about when you run the first two pairs? ie the first four queries out of the six?
Avatar of MrTV

ASKER

Hi TerryAtOpus

DROP TABLE IF EXISTS chg ;

CREATE TABLE chg AS
SELECT sename."Date",
    sename.name,
    sename."Open",
    sename."Low",
    sename."Close",
    COALESCE(lag(sename."Open") OVER (PARTITION BY sename.name ORDER BY sename.name), sename."Close") AS lag_start
   
   FROM sename
  ORDER BY sename.name, sename."Date" DESC;


does not work
SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The problem is that it is:
BEGIN; DROP TABLE; CREATE TABLE; COMMIT
from visual tool