Teradata ignore error for multiple queries in same window - teradata

I'm running multiple drop statements directly using Teradata SQL Assistant in the same query window.
For example:
DROP TABLE publish.a;
DROP TABLE publish.b;
DROP TABLE publish.c;
DROP TABLE publish.d;
The problem is that some of the tables may not be present due to which the code will stop executing and will throw an error "Drop table failed [3807]"
I've tried using the .goto label but I am unable to find a way to simply "continue with the next statement"
I even tried
.set maxerror 100;
.set retry on;
.set errorlevel 3807 severity 0;
with no luck.

Related

Using DBMS error log, how can I bulk insert values from one table into another skipping (but logging) errors?

I am trying to bulk insert rows from one table to another. I want to skip any errors that occur while doing this but log them as well. I used the following PL/SQL command to create an error log table for the table I am trying to insert all the values into:
BEGIN
DBMS_ERRLOG.create_error_log (
dml_table_name => 'ROBOT_ID_TOOL_DUMP_IDPK.TEST'
, skip_unsupported => TRUE);
END;
I then do a simple insert with logging turned on:
INSERT INTO table2
SELECT * FROM table1
LOG ERRORS INTO ERR$_table2;
The logging works but my insert is stopping, and rolling back after the first exception is hit (PK or unique constraint for example). I don't want to rollback when an exception is encountered though, I want that row to be skipped, and to continue trying to insert all remaining rows (but logging the problem row). I thought that is what the skip_unsupported parameter was doing. I have tried setting this value to FALSE and am still encountering the same issue.
I missed a step on my insert.
INSERT INTO table2
SELECT * FROM table1
LOG ERRORS INTO ERR$_table2 REJECT LIMIT UNLIMITED;
The REJECT LIMIT UNLIMITED flag Continues through every error.

Unable to delete a MySQL InnoDB table

I am using MySQL 5.1.56
I have a DB with about 70 tables and I have an issue with a particular corrupted table e.g. Table_X
When I try to access the table
mysql> select * from Table_x;
ERROR 1105 (HY000): Failed to read from the .par file
I am unable to add partitions to the table.
When I try to drop the table I see the below errors.
mysql> drop table Table_X;
ERROR 1051 (42S02): Unknown table 'Table_X'
The create query gives the error: ERROR 1050 (42S01): Table 'Table_X' already exists.
In my DB files locations, I can see the corresponding Table_X.frm, Table_X.ibd and Table_X.par files. But in addition, I also see a file '#sql-Table_X.frm' in the location.
When I check the 'Tables' table in the information_Schema DB, the Engine value is NULL for this particular table, where as it should have been InnoDb.
The table seems to be corrupted somehow.
I tried the Flush-tables command,but that did not help as well. I am still unable to drop and recreate the table.
I do not wish to take a backup of this particulate table, but I need to preserve other tables of the database. Is there any way, I can just recreate this individual table without having to restore the entire Database.
You can try to repair the table with the following statement :
REPAIR TABLE Table_X;
Take care, such query can induce a loss of data, but since you are trying to DROP the table, I guess this is not a matter for you.
You could also try to use the FRM file as a source for your table with
REPAIR TABLE Table_X USE_FRM;
PS : Can you give us the result of the following query ?
CHECK TABLE Table_X;
References :
https://www.tutorialspoint.com/mysql/mysql_repair_table_statement.htm
https://www.tutorialspoint.com/mysql/mysql_check_table_statement.htm

sqlite3 got syntax error while executing vacuum in a trigger

I'm using sqlte3.8.8, trying to create a trigger to clean old data. Here is the SQL that I put in:
CREATE TRIGGER "main"."NewTrigger" AFTER INSERT ON "historydata"
BEGIN
delete from historydata where id in (select id from historydata order by id limit 100000);
vacuum;
END;
But I got Syntax error on "vacuum;".However, it works fine in sqlite command line.
Is it the case that "vacuum" cannot be used in a trigger?
The documentation shows that only UPDATE/INSERT/DELETE/SELECT statements are allowed in a trigger body.

sqlite: dropping a table in a transaction?

I have a simple, single table sqlite3 database file that has exactly one table. There are no keys, foreign or domestic. There are no triggers. I have the following workflow:
If the database file exixts open it.
Start exclusive transaction
Select all rows from the table in order.
Operate on each row.
Delete each operated-on row.
When done, count the number of remaining rows in the table, if 0 then DROP the table then unlink the database file
Commit or Rollback the transaction
The drop-table always fails with the message that the table is locked. I've seen a couple of other posts that suggest that there could be open statement handles or other cruft lying around. Since I am using "sqlite_exec()"s for all of this I do not have any open DB anything except the DB handle itself.
Is drop table not allowed in transactions?
When dropping a table, you get the "table is locked" message when there is still some active cursor on the table, i.e., when you did not finalize a statement (or did not close a query object in whatever language you're using).

SQLite "Drop table" error message: "SQL logic error or missing database"

I am running a SQLite database in memory and I am attempting to drop a table with the following command.
DROP TABLE 'testing' ;
But when I execute the SQL statement, I get this error
SQL logic error or missing database
Before I run the "Drop Table" query I check to make sure that the table exists in the database with this query. So I am pretty sure that the table exists and I have a connection to the database.
SELECT count(*) FROM sqlite_master WHERE type='table' and name='testing';
This database is loaded in to memory from a file database and after I attempt to drop this table the database is saved from memory to the file system. I can then use a third party SQLite utility to view the SQLite file and check to see if the "testing" exists, it does. Using the same 3rd party SQLite utility I am able to run the "Drop TABLE" SQL statement with out error.
I am able to create/update tables without any problems.
My questions:
Is there a difference between a memory database and a file database in SQLite when dropping a table?
Is there a way to disable the ability to drop a table in SQLite that I may have accentually turned on somehow?
Edit: It appears to have something to do with a locked table. Still investigating.
You should not have quotes in your DROP TABLE command. Use this instead:
DROP TABLE testing
I had the same problem when using Sqlite with the xerial jbdc driver in the version 3.7.2. and JRE7
I first listed all the tables with the select command as follows:
SELECT name FROM sqlite_master WHERE type='table'
And then tried to delete a table like this:
DROP TABLE IF EXISTS TableName
I was working on a database stored on the file system and so it seems not to effect the outcome.
I used the IF EXISTS command to avoid listing all the table from the master table first, but I needed the complete table list anyway.
For me the solution was simply to change the order of the SELECT and DROP.

Resources