I am running the following code for 40000 rows
update L02_A_AVOX_DATA
set PWC_Exclusion_Flag = (select PWC_Exclusion_Flag from result
where L02_A_AVOX_DATA.PWC_SEQ_AVOX = result.PWC_SEQ_AVOX);
The code is running for 20 minutes . Dont know whats the error.
Can anyone help me in it
Can you try the following query, maybe that helps:
MERGE INTO L02_A_AVOX_DATA n USING (
SELECT PWC_Exclusion_Flag , PWC_SEQ_AVOX
FROM result
) o ON (n.PWC_SEQ_AVOX = o.PWC_SEQ_AVOX)
WHEN MATCHED THEN
UPDATE SET n.PWC_Exclusion_Flag = o.PWC_Exclusion_Flag;
Related
We have a rather simple query that gets stuck:
UPDATE BRI_PRINT_DOCUMENT pd
SET PRINT_STATUS_ID = 6
WHERE pd.PRINT_STATUS_ID = 1
AND pd.DOCUMENT_TYPE_ID IN (
SELECT jd.DOCUMENT_TYPE_ID
FROM BRI_JOBTYPE_DOCUMENTTYPE jd
WHERE jd.JOB_TYPE_ID = 2);
COMMIT;
The following query doesn't help:
UPDATE (SELECT *
from BRI_PRINT_DOCUMENT PD
INNER JOIN BRI_JOBTYPE_DOCUMENTTYPE BJD
on PD.DOCUMENT_TYPE_ID = BJD.DOCUMENT_TYPE_ID
AND JOB_TYPE_ID = 2
AND PRINT_STATUS_ID = 1) joined
SET joined.PRINT_STATUS_ID = 6;
We have problems understanding the problem as the following query is fast:
SELECT * FROM BRI_PRINT_DOCUMENT pd
WHERE PRINT_STATUS_ID = 1
AND pd.DOCUMENT_TYPE_ID IN (
SELECT jd.DOCUMENT_TYPE_ID
FROM BRI_JOBTYPE_DOCUMENTTYPE jd
WHERE jd.JOB_TYPE_ID = 2);
Any idea what causes the problem?
Although me and my colleague had the problem of the hanging query through sql developer / Datagrip, the problem got magically resolved when the db admin executed the exact same query with Toad.
There was no table lock, the db admin didn't receive any alert of problems and we have no idea what caused the problem.
Thanks Oracle :-)
Note: there are only a few thousands of records in our dev database.
Explain plan:
With 20+ years of experience with MS Access and SQL Server, I'm not a novice with respect to SQL, but I am new to PostgreSQL and I have encountered an issue that makes me feel like a complete noob. I have a simple UPDATE query in which I want to update the destination table d with data from the source View m:
UPDATE chgman.tc_data
SET reporttime = m.reporttime, endtime = m.endtime,
itismessage = m.itismessage, shortdesc = m.shortdesc,
longdesc = m.longdesc, severity = m.severity,
tc_source = m.tc_source, tc_state = m.tc_state,
ushr_state = m.ushr_state, mainroad = m.mainroad,
start_location = m.start_location, end_location = m.end_location
FROM
chgman.tc_matched_raw AS m
INNER JOIN
chgman.tc_data AS d ON d.tc_id = m.tc_id;
The result of the query is that EVERY row in table d is populated with data from the FIRST row of View m.
I am prepared for the embarrassment - please enlighten me as to what I have done wrong...
The from/update in Postgres works a bit differently from SQL Server/MS Access.
This should do what you want:
UPDATE chgman.tc_data d
SET reporttime = m.reporttime, . . .
FROM chgman.tc_matched_raw m
WHERE d.tc_id = m.tc_id;
You don't repeat the table in the FROM clause -- that is a new reference to the table.
I'm writing a database and I simply want to update tblSchedule with the ItemNo from tblStock but I get an error when trying to run this:
Operation must be an updatable query
I can't seem to figure out why it's not working.
UPDATE [tblSchedule]
SET [tblSchedule].ItemNo =
(SELECT DISTINCT Item
FROM [tblStock], [tblSchedule]
WHERE [tblStock].Bookcode=[tblSchedule].[PartCode]
)`;
Any help would really be appreciated
You are missing a closing bracket in your SQL.
UPDATE [tblSchedule] Set
[tblSchedule].ItemNo = (
SELECT DISTINCT Item
FROM [tblStock], [tblSchedule -- Missing closing bracket
WHERE ((([tblStock].Bookcode)=[tblSchedule].[PartCode]))
)
Try closing the bracket on tblSchedule.
I do not have an Access database to test this on for you, though.
My guess is your inner SELECT is returning 2 records instead of one.
You can do this to validate.
SELECT Items.ItemNo, count(*) total
FROM
(
SELECT DISTINCT Sc.ItemNo, St.Item
FROM
[tblSchedule] Sc INNER JOIN
[tblStock] St ON Sc.PartCode = St.Bookcode
) as Items
GROUP BY Items.ItemNo
HAVING count(*) > 1;
Due to the simplicity of what I wanted I've gone down the Dlookup route which works successfully.
UPDATE [tblSchedule], [tblStock] SET [tblSchedule].ItemNo = DLookUp("Item","[tblStock]","[tblStock].Bookcode='" & [tblSchedule].[PartCode] & "'")
WHERE (([tblStock].[Bookcode]=[tblSchedule].[PartCode]));
It's probably not the best method but due to the small amount of records it updates (252) it works perfectly without any noticable time delay.
Thanks Again!
Chris
SELECT Distinct lu.ObjectID
FROM LAND_USE_EVW as lu
WHERE NOT EXISTS (SELECT LAND_USE_EVW.OBJECTID
FROM LAND_USE_EVW, MUNICIPALITIES_EVW
WHERE LAND_USE_EVW.Shape.STCentroid().STIntersects(MUNICIPALITIES_EVW.shape) = 1
)
I was trying to get a result that opposite of below
select LAND_USE_EVW.OBJECTID
from LAND_USE_EVW, MUNICIPALITIES_EVW
where LAND_USE_EVW.Shape.STCentroid().STIntersects(MUNICIPALITIES_EVW.shape) = 1
= 0 didn't work therefore I'm trying to come up with other idea.
But result shows nothing. No errors or warning.
found answer
WHERE NOT EXISTS (SELECT LAND_USE_EVW.OBJECTID
FROM LAND_USE_EVW, MUNICIPALITIES_EVW
removing LAND_USE_EVW from FROM LAND_USE_EVW solve the problem
The script below returns the 01427 error that the single row sub-query returns more than one row. The rownum<2 gets a few rows updated. The obvious solution is looping through with pl/sql, but I am trying to determine if there is a SQL only solution.
UPDATE ldl.clens le
SET master_song_id =
(SELECT cf.song_id#
FROM lt.master_songs cf
WHERE le.lot_id = cf.lot_id
AND song_id#_fk =
(SELECT msc_songs.song_id#
FROM lt.msc_songs
WHERE msc_songs.song_name = le.song_name)
---- AND ROWNUM < 2
);
Any and all help and suggestions deeply appreciated!
MD
I'm not sure I grasped the relation between the tables, but if I did, you can use below UPDATE:
UPDATE ldl.clens le
SET master_song_id =
(SELECT cf.song_id#
FROM lt.master_songs cf
JOIN lt.msc_songs ms ON (cf.song_id#_fk = ms.song_id#)
WHERE
ms.song_name = le.song_name
AND le.lot_id = cf.lot_id)
;
It will work if msc_songs.song_name and master_songs.lot_id will give you a unique master_songs.song_id#.