How to group Teradata DDL/DCL statement (in a stored procedure) in a transaction so that all works or nothing? For example
Begin Transaction
Create User aUser ...;
Grant some permissions to aUser;
End Transaction;
In the above example either both create user and grant statements are executed or both rollback in case of an error.
Thanks
Related
I have a query to remove property from a node but whenever i try to remove i get the following error
neobolt.exceptions.NotALeaderError: No write operations are allowed directly on this database. Writes must pass through the leader. The role of this server is: FOLLOWER
Here is the query
MATCH (n) WHERE n:`BA` and n:`test 2` Remove n.`test 50.title`,n.`test 2.Abc`,n.`test 50.Abc
you have to execute it with 'write role operation'
I have created a Babelfish-enabled Postgres database in RDS.
I connected with SSMS and created a Database named 'demo'.
Within 'demo' I created a Schema named 'biz'.
I created my tables and stored procedures in the 'biz' schema.
The stored procedures used unqualified table names.
Finally, I wrote a .Net program to do some testing.
I use the System.Data.SqlClient Connection and Command classes and I can connect to the database.
When I execute a stored procedure I get the 'relation "X" does not exist.' error.
If I alter my stored procedure and qualify the table names with the 'biz' schema the error goes away.
How do I avoid having to qualify the table names with the schema?
For example:
After creating a Babelfish enabled Postgres cluster I executed these statements in SSMS:
create database demo
use demo
create schema biz
create table [biz].[cities](
[city] varchar(128),
[state] varchar(128)
)
create procedure [biz].[p_getcities] as
begin
select * from cities
end
insert into [biz].[cities](city, state) values ('Portland', 'OR')
insert into [biz].[cities](city, state) values ('Richmond', 'VA')
exec [biz].p_getcities
And I get this error message after running p_getcities:
Msg 33557097, Level 16, State 1, Line 21
relation "cities" does not exist
When I switch to pgAdmin and try to run the stored procedure like this:
CALL biz.p_getcities()
I get a similar error:
ERROR: relation "cities" does not exist
LINE 1: select * from cities
^
QUERY: select * from cities
CONTEXT: PL/tsql function biz.p_getcities() line 2 at SQL statement
SQL state: 42P01
However, when I set the search_path like this:
set search_path to biz
And the execute the stored procedure I get the expected results:
Portland OR
Richmond VA
Is there an equivalent to search_path in Babelfish?
This explanation has been provided by Rob Verschoor of rcv-aws
What is happening here is that the name resolution inside the procedure biz.p_getcities does not correctly resolve the table name. It resolves it to 'dbo' schema while it should resolve it to 'biz' schema. As you noted, this is related to the search_path setting, and this is not set correctly in this case.
This is a known bug and we hope to fix it soon.
Until then, the workaround is to qualify the table name with the schema name, i.e. select * from biz.cities
I have execute procedure in Firebird and calling from asterisk.
The transaction not commited after complete procedure, but after asterisk$> reload transaction commited.
Thank you very much.
Data manipulation language statements are not committed automatically.
You must issue a "commit" statement to commit any DML changes to the database.
If after reload you've seen the execution results commited, be sure that when going down for reload asterisk transaction handler has issued the commit statement.
I have created a stored procedure PROCA in Database A with user USERA and given
execute permission to USERB and I could execute this stored proc in Database A when logged in with USERB.
Now I logged in to Database X and created a dblink Akink and this dblink conntects to
Database A with user USERB. Now when I execute stored proc using below syntax ,
it got executed without any error but whatever DML operations stored proc have done,
are not committed.
Code to invoke stored proc from Databse X
declare
begin
USERA.PROCA#Alink();
COMMIT;
end;
Please suggest what could be the issue.
It seems there are no good solutions for such situations.
But here is a suggestion for you; try using this:
Exec dbms_utility.exec_ddl_statement#db_link('some ddl sql statment');
For example:
Exec dbms_utility.exec_ddl_statement#db_link('truncate table test_tab');
this particular stored procedure does an archive purge:
1) select tokens from transactional db
2) put tokens in temp table
3) loop through tokens:
3.1)using tokens from temp table, retrieve data from transactional tables and insert to tables in a separate archive db (via federation)
3.2) COMMIT inserts.
3.3) then using same token this time delete the data from the transactional
3.4) COMMIT deletes.
2 phase commit allows us to have just one commit at the end of the loop
my question is how to simulate scenarios to make proc fail in the insert phase or delete phase? this is to ensure that even though run has failed, data retains integrity - no half-processed tokens or such.
to force a run-time error, I usually put in a SELECT 0/0 in the code. just put this in before the COMMIT of your choice and watch the fireworks that result!
If you have unique keys involved you can put a record in place that would cause a duplicate key violiation.
Hope this will help somebody else!
I just recently found that the best way was via signals.
In the middle of the delete phase, I put in an error signal so process would fail on that token and exit the loop, so it should rollback whatever it has inserted in the insert phase for that token.
DECLARE rollback_on_token_101 CONDITION FOR SQLSTATE '99001';
inside the loop middle of delete phase
IF TOKEN_SUCCESS_COUNT=100 THEN
SIGNAL rollback_on_token_101
SET MESSAGE_TEXT = 'rolling back on mid-delete phase on token # 101 ';
END IF;