Questions tagged [error-handling]
The error-handling tag has no usage guidance.
143
questions
0
votes
0
answers
14
views
MySQL 8: show deprecated error only as warning
I'm migrating MySQL from 5.7 to 8.0.32.
I know character set utf8mb3 and its collations are deprecated. But we have lots of functionality and data with utf8mb3,
and we don't have more time to change ...
1
vote
1
answer
129
views
Handle partial failures in a transaction (commit selectively) in MSSQL
I am doing a batch update where I process records sequentially (User 1, User 2 etc). Each record has multiple update queries associated to it. I need to skip if there is a data issue for an individual ...
2
votes
1
answer
165
views
How to cause a SQL Server database integrity error
I have created a stored procedure that uses dbcc checkdb on all userdatabases, if there are any errors detected it then collates the errors and formulates a html table and sends an html email to ...
1
vote
1
answer
177
views
Lost connection to the database during COMMIT query: did the transaction succeed or not?
PROBLEM
I recently encountered the error 2013 in MySql (Lost connection to MySQL server during query) while executing the COMMIT statement for a transaction (the previous update statements succeeded). ...
0
votes
2
answers
815
views
Try Catch w/Transaction and executing stored procedures
I need to create an error-handling method for a couple of Stored Procedures.
Proc1
CREATE PROCEDURE dbo.Proc1
AS
BEGIN TRY
BEGIN TRANSACTION
EXEC Proc2
INSERT INTO tableA (col1, col2) ...
0
votes
1
answer
471
views
Logging in error states in Postgres transactions
I'm currently working on rebuilding some SQL Server stored procedures in Postgres, but I have the following hangup
CREATE OR REPLACE PROCEDURE public.math_proc ()
LANGUAGE plpgsql
AS $$
BEGIN
...
0
votes
2
answers
203
views
WHILE EXISTS Error Handling/ Raise Error
I am adding a step in my SQL job where it does a WHILE EXISTS check for me before executing the last step. What it does is it will wait for 15minutes to see if the table I am checking has been ...
-2
votes
1
answer
611
views
PSQL avoid insert failing because a trigger failed
I want to put a trigger on a table, the code itself could work sometimes, while sometimes it might fail unexpectedly.
So I need the data to get inserted on the table regardless if one of its triggers (...
0
votes
1
answer
1k
views
Routinely deleting data from tables using stored procedure
I've created a maintenance stored procedure to delete data older than 30 days on events table.
What are the best practices for deleting data?
I've encased the procedure with
error handling, i.e. TRY......
0
votes
0
answers
35
views
Filter out non date values from date values in postgresql
I receive data in text format for dates, some wrong entries are also present for eg.
date 30-02-2022 which doesn't exist.
So when I try to cast text into dates, it fails with an error.
I thought of ...
6
votes
1
answer
629
views
Why do permission errors doom a transaction with XACT_ABORT set to OFF and ANSI_WARNINGS set to ON?
Consider the following T-SQL in which the user doesn't have permission to execute SP_TRACE_GENERATEEVENT:
SET XACT_ABORT OFF;
SET ANSI_WARNINGS ON;
BEGIN TRANSACTION;
BEGIN TRY
EXEC ...
-4
votes
1
answer
78
views
Finding the errors in SQL and interpreting what the SQL codes mean
Find all 5 errors in the SQL script below and explain what the script is trying to do
select
A.BIZ_DT,
A.ACTL_PARENT_SVC_NUM,
A.DIRCTN_IND,
A.BUS_STOP_CD,
A.BUS_STOP_ARRVL_TM,
A.OPR_ID_NUM,
A.REG_NUM,
...
2
votes
2
answers
541
views
How to simulate error with MSG = 0 on Sql Server?
I need to simulate error on Sql Server:
“Msg 0, Level 20 A severe error occurred on the current command”
because our developers have to handle it in application.
How can I simulate/trigger this kind ...
1
vote
2
answers
2k
views
Postgres: Insert all valid data into a table while logging errors
I am attempting to devise a method that will enable me to load data into a table which will load all valid data and log the invalid records. Ideally, I'd like to do this without looping through the ...
0
votes
0
answers
165
views
How to save the error returned by a stored procedure
I am trying to figure out how to get the error message returned from the proc sys.sp_testlinkedserver rather than the non-descriptive message returned by ERROR_MESSAGE().
The proc's message is:
OLE ...
1
vote
1
answer
4k
views
How to use user defined exception - PostgreSQL Function
Can you please provide syntax for to use user defined exception in PostgreSQL function?
Suppose I want to handle below user defined exception.
SQL Error [22023]: ERROR: password is too short.
There ...
3
votes
3
answers
12k
views
How to solve error "ORA:01-006 :bind variable does not exist" when working with bind variables?
I have a table with below structure and data :
create table TEST_TABLE
(
item_number NUMBER,
item_name VARCHAR2(50),
item_col VARCHAR2(50),
item_pol VARCHAR2(50)
)
Sample data:
...
5
votes
2
answers
393
views
Multiple Set Quoted_identifier within one script takes the last one?
I'm using SQL Server 2019 and just found a weird behaviour.
Research has not gotten me anywhere further.
Can someone please explain this behaviour?
SET QUOTED_IDENTIFIER ON;
if ((256 & @@options) ...
4
votes
3
answers
997
views
MS SQL Server 2014: which stored procedure is my error in?
As a general question or three on Microsoft SQL Server 2014, that perhaps I should know the answer to already, or even perhaps did once -
When my stored procedures run other stored procedures, how can ...
0
votes
0
answers
60
views
Get real error from backup job failure instead of backup terminating abnormaly
I've had log backup jobs fail for a few different reasons lately. When I go to the job it tells me backup terminated abnormally. However, when I run the backup script in SSMS it will tell me the ...
14
votes
1
answer
21k
views
Is "deadlock detected" really an error? Should I be suppressing them after handling them?
A while ago, I spent a nightmarish number of weeks dealing with "deadlock detected" and trying to figure out how to handle it. I ended up finally handling it in such a manner that my code is ...
-2
votes
2
answers
133
views
Best way to double check query results are right on large tables [closed]
When you write SQL query between big tables what is a good way to check that you have the correct query when the resulting table is 2000+ lines?
2
votes
3
answers
3k
views
BULK INSERT continue on PRIMARY KEY error
I get a CSV file with a several million records every few days. I need to insert them into our database. What I do is quite straightforward:
BULK INSERT dbo.activity
FROM 'C:\tmp\activity.csv'
WITH (
...
0
votes
2
answers
264
views
How do I make PostgreSQL not log specific errors?
ERROR: deadlock detected at character 13
My PG log is full of this, but the thing is, I already handle it (after years of frustrations) in my application. I detect them and repeat until they go ...
1
vote
1
answer
1k
views
TSQL success or failure result of EXEC dynamic SQL
Based on the following code:
/* This SP takes a query and a unique temporary table name as input...
The outputs is a string with the command to create the tmp table based on the query that is given ...
0
votes
1
answer
167
views
TRY/CATCH only reports the last (and most useless) error
(This is SQL Server 2016 SP2-CU12.)
When running this command interactively, I see the quite useful Msg 3035, Level 16, State 1.
BACKUP DATABASE @DB TO DISK = @targetfile
WITH DIFFERENTIAL, RETAINDAYS ...
1
vote
2
answers
438
views
How to make MySQL 8 alert when integer overflow happens during INSERT ... ON DUPLICATE KEY?
Let's consider we have a simple table with auto-incrementing integer ID and some unique column:
CREATE TABLE `test` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`value` tinyint DEFAULT NULL,
...
0
votes
2
answers
621
views
How to catch all the errors happening during the execution of an SQL file containing multiple INSERT INTO statements to insert multiple rows?
I've got a sql file TW_popul.sql containing multiple INSERT statement:
INSERT INTO conversion_fee (FEE_ID, FEE_AMOUNT, DISCOUNT_AMOUNT, FEE_TYPE, PAYMENT_ORDER_ID)
VALUES (32353357, 8.67, 0, 'com....
6
votes
1
answer
2k
views
Custom error code class and numbers for Postgres stored functions
I'm writing a collection of stored functions in Postgres 11.5, and want to RAISE EXCEPTION when various pre-conditions are not met. For example, a null or empty string with a string is required, or an ...
-1
votes
1
answer
312
views
Every Attempt at Error Handling Fails with GET
UPDATED (12.3.2019)
I'm using MySQL 8.x and every attempt at putting any error handling that provides internal details fails on the "GET" (red highlight) stating:
GET is not valid at this position
...
3
votes
1
answer
219
views
Getting all undeclared variables from query
Imagine you try to run the following query:
SELECT *
FROM dbo.Customers c
WHERE id = @id
AND dateTimeCreated = @date
You'll get an error message along the lines of Must declare the scalar ...
1
vote
1
answer
153
views
Do a lot of error checks affect query performance and is it bad practice?
If I have a stored procedure with a handful of error checks that come before the queries are executed and throw exceptions as necessary, could this affect performance? Is it bad practice to do this?
...
0
votes
0
answers
31
views
Is it possible to create an SQL transaction that rollbacks on syntax errors?
In may day-to-day job, I often have to create SQL files containing minor changes (no DDL operation usually) in order to migrate those to production databases easily.
The problem is, even with syntax ...
2
votes
0
answers
283
views
Catching QUOTED_IDENTIFIER Errors in Trigger without aborting transaction
Is there a way to catch a QUOTED_IDENTIFIER error without failing the transaction?
I have assembled a minimal test case here. The trigger must have SET QUOTED_IDENTIFIER ON because it uses XML data ...
24
votes
1
answer
62k
views
Try catch equivalent in Postgres
Do we have a try catch equivalent in Postgres? I have written some user defined functions that are called by trigger. I (don't) want to ignore errors so that flow does not get interrupted.
6
votes
1
answer
2k
views
SQL Server - TRY/CATCH does not work in certain cases
How can I write guarded code that invokes the CATCH code block in every expected* case (without doing funky junk like wrapping everything in dynamic SQL)?
For example, this does not work:
Define a ...
0
votes
1
answer
466
views
how to convert from raiserror to throw in the current context?
I have a function that checks is the file is present on disk in an specific location.
Using that function I am checking for the latest backup, in the code below.
If we don't have a backup anymore, ...
2
votes
1
answer
174
views
why the processing is sometimes terminated , sometimes not
DECLARE @Error int;
INSERT INTO Person.BusinessEntityContact
(BusinessEntityID
,PersonID
,ContactTypeID)
VALUES
(0,0,1);
SELECT @Error = @@ERROR;
PRINT ‘The Value of @Error is ‘ + CONVERT(varchar,...
0
votes
1
answer
679
views
Why is my TRY CATCH block in SQL Server immediately exiting on error completely ignoring the remaining code in the block, including my error handling?
Below is a snippet of my TRY/CATCH logic within a stored procedure with error handling (I did not include all of the DECLARE statements). This is being ran within a stored procedure, however I am ...
2
votes
1
answer
515
views
Object id error in sql server
I want to know the object referenced as an associatedObjectId in a deadlock graph, so I ran the below query:
SELECT OBJECT_NAME(1234560112364076)
I get the following error:
Arithmetic overflow ...
1
vote
0
answers
642
views
Can I force a LOAD DATA LOCAL statement to abort if an error is not loaded?
I am trying to load a CSV file into a MySQL table with the load data local statement. After loading it, the statement reports
Query OK, 1030 rows affected, 7314 warnings (0.03 sec)
Records: 1043 ...
4
votes
1
answer
394
views
Does the "don't use errors for flow control" axiom apply to postgres?
In traditional programming there is an axiom that states, "do not use errors for flow control". A general example is to throw an error then catch the error instead of using an ordinary conditional ...
1
vote
1
answer
8k
views
SQL Creating Error Log Table Benefits
We are conducting a datawarehouse project, moving data from Staging database to Kimball Data Warehouse.
What is the purpose of creating a custom stored procedure Error Log Table?
I am seeing a lot ...
0
votes
0
answers
6k
views
SQL Server Error 14013 - This database is not enabled for publication
I am trying to configure a database publication with T-SQL.
use master
exec sp_replicationdboption
@dbname='anun',
@optname=N'publish',
@value = N'true';
It runs successfully and I see ...
2
votes
0
answers
681
views
How get process that is locking Database on SQLite?
I'm developing a iOS app using SQLite. I've got a class to manage SQL's operations, basically read, write and update. In many cases I get a SQLITE_BUSY error, so I want know which process is using the ...
0
votes
1
answer
2k
views
Find if Stored Procedure Error
Is there a method in T-SQL to see if error occurred in Stored Procedure, without the use of @Output or try catch?
We have a lot of legacy code 200+ stored procedures. I have seen @Output method and ...
1
vote
1
answer
152
views
How to index of filter extended event files in Sql Server
I am collecting errors data using the error_reported event and saving the data on XEL files. The problem is that there are hundreds of thousands of errors over there and querying them can take a lot ...
1
vote
2
answers
665
views
Impossible to log errors after dooming a transaction within an INSERT-EXEC statement
We have a stored procedure that does some work within a transaction, wrapped within a stored procedure that returns some result data using the INSERT-EXEC method of sharing data.
After observing the ...
1
vote
1
answer
486
views
Should SQL Server 2000 throw an error if update statement fails within a SP?
I'm troubleshooting an issue on SQL Server 2000 where it appears that a update statement in a stored procedure failed, and the check for @@ERROR <> 0 didn't catch it, so the transaction was ...
0
votes
2
answers
150
views
how to run once a bunch of generated scripts with exception handling?
Before I restore a database, I need to save the contents of a table called dbo.ref_systemSettings if it exists.
So I created a script that calls a procedure that will save the contents of this table ...