How to disable an existing Trigger in SAP HANA Database? - triggers

I want to disable an existing trigger in SAP HANA database. Trigger name is UPDATE_SERIAL_CHANGELOG
I tried executing below script however I'm getting error:-
ALTER TRIGGER "CM_DB"."TRIGGER UPDATE_SERIAL_CHANGELOG" DISABLE;
Error:-
Could not execute 'alter trigger "CM_DB"."TRIGGER UPDATE_SERIAL_CHANGELOG" disable'
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "trigger": line 1 col 7 (at pos 7)
Please assist.
Thanks

HANA helps in disabling triggers
ALTER TABLE "table name" DISABLE TRIGGER "trigger name";

SAP HANA does not support altering or disabling of triggers.
You can CREATE (OR REPLACE) or DROP them.

Related

"create or replace trigger" not available on AWS RDS/Postgres

I have the following:
CREATE OR REPLACE TRIGGER trigger_commands
AFTER INSERT ON commands
FOR EACH ROW EXECUTE PROCEDURE on_commands_change();
it works on a local Postgres instance, but fails on AWS with:
[42601] ERROR: syntax error at or near "TRIGGER"
however, if I remove the 'OR REPLACE' part:
CREATE TRIGGER trigger_commands
AFTER INSERT ON commands
FOR EACH ROW EXECUTE PROCEDURE on_commands_change();
then RDS accepts it. Why is that? and what would be the best way to update the trigger at every code restart?
It's most likely a Postgresql version mismatch, CREATE OR REPLACE TRIGGER works only on Postgresql 14 (see documentation, 14 and 13).
I'd suggest to use DROP TRIGGER IF EXISTS then CREATE TRIGGER for backwards compatibility.

Install4j - Is it possible to run TSQL queries?

When working with Server-Sql, sometimes it needs to use Transact-SQL queries. Is it possible to execute it through Install4j?
EDIT
I'm using the Server SQL JDBC driver: - com.microsoft.sqlserver.jdbc.SQLServerDriver.
When I'm trying to execute the following script in the SSMS it works without any problem:
USE [${installer:DbName}]
GO
CREATE USER [Guest] FOR LOGIN [Guest]
GO
USE [${installer:acDbName}]
GO
ALTER ROLE [db_owner] ADD MEMBER [Guest]
GO
, but when executing it with the "Execute SQL script" I get the following error: com.install4j.runtime.beans.actions.jdbc.ExecuteSqlScriptAction [ID 8123]: Error executing script line "U", error message: "Could not find stored procedure 'U'."
When enabling the statement delimeter with ; I'm getting the next error:
"Incorrect syntax near 'GO'."
It depends on whether the JDBC driver that you are using can handle TSQL or not, install4j does not have support for specific databases.

pgAdmin 4 does not create functions with geometry

I started recently using pgAdmin 4 after having used pgAdmin 3 for a long time.
The problem I have now is that I cannot replace existing functions that reference geometry objects. I am on Windows 10, and the current version of pgAdmin 4 is 2.1.
The PL/pgSQL function already exists in the database and it was created with flyway, psql or pgAdmin 3, and it works.
The PostGIS extension is enabled.
Now I go in pgAdmin 4 and use the same login as ever, choose "Scripts"->"Create script" for the function, and then click F5 - "run Script" to create it.
What I get is an error:
ERROR: type "geometry" does not exist
LINE 22: v_location geometry;
The same operation in pgAdmin 3 gives no error.
The function has the search_path set correctly and can be created in pgAdmin3 and psql.
Actually I can create a dummy function in the query tool in pgadmin4 and compile it. See below:
set search_path=res_cc_01,public;
create or replace function test() returns text
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
COST 100
set search_path=res_cc_01,public
AS
$BODY$
DECLARE
v_g geometry := ST_GeometryFromText('POINT(142.279859 -9.561480)',4326);
begin
return 'xxx'::text;
end;
$BODY$
Only when recompiling through Scripts->Create Script then F5 ( Execute ) I got the error.
What is the problem here?
I could not find a similar problem on the net, nor into the manuals. But I haven't read them all.
You're certainly missing the postgis extension in the current database. If you already have it installed in your server, just execute the following command to create the extension and so the missing data type:
CREATE EXTENSION postgis;
If it happens to be that you don't have it installed in your database server, you can find the installation instructions to many operating systems here.
The problem is caused by the way pgadmin 4 shows the plpgsql code when using Scripts-> Create Script.
It adds unneeded quotes to the paths in the search_path directive that makes the entire search_path invalid. With an invalid search_path the compiler will not find the available extensions.
We actually have an item with PGAdmin4 with Scripts->Create Script malfunction.
In PgAdmin 3 the search_path directive used in the function was showed as alter function statement but in a correct form.
Many thanks to Jim Jones for the precious analysis on this problem.

Creating view in DB2 LUW with Liquibase

I'm using Liquibase 3.5.3 to create a view in DB2 LUW 11.0.
I set "replaceIfExists" property to true and at runtime it give me an "replaceIfExists is not allowed on db2" error.
I know that officially this property is not supported for DB2 in Liquibase but the database api allows it (I manually execute sql script with create or replace and works fine).
There is some workaround to run this scripts in DB2 or maybe can you implement this feature?
Example:
CREATE OR REPLACE myView AS (
SELECT * FROM myTable
)
I would put that script into a file and then include the file from within liquibase with the runOnChange="true" for the changeSet
<changeSet author="arthur.dent" id="42" runOnChange="true">
<sqlFile path="create_view.sql"
encoding="UTF-8"
relativeToChangelogFile="true"
stripComments="false"
splitStatements="false"/>
</changeSet>
Because of the runOnChange, Liquibase will include a checksum of the actual SQL file and will only run it if the definition of the view changed.
Another option is to use runAlways="true" instead and then the view will be re-created every time you run Liquibase. This would be necessary to automatically pick up changes in the underlying table(s).

Rename SQL Azure database?

How can i rename the database in sql Azure?
I have tried Alter database old_name {MODIFY NAME = new_name} but not worked.
Is this feature available in SQL Azure or not?
Just so people don't have to search through the comments to find this... Use:
ALTER DATABASE [dbname] MODIFY NAME = [newdbname]
(Make sure you include the square brackets around both database names.)
Please check that you've connected to master database and you not trying to rename system database.
Please find more info here: https://msdn.microsoft.com/en-US/library/ms345378.aspx
You can also connect with SQL Server Management Studio and rename it in Object Explorer. I just did so and the Azure Portal reflected the change immediately.
Do this by clicking on the database name (as the rename option from the dropdown will be greyed out)
Connect with SQL Server Management Studio to your Azure database server, right-click on the master database and select 'New Query'. In the New Query window that will open type ALTER DATABASE [dbname] MODIFY NAME = [newdbname].
It's Very simple for now - Connect to DB via SQL Management Studio and Just rename as you generally doing for DB [Press F2 on DB name]. It will allow you to do this and it will immediately reflect the same.
I can confirm the
ALTER DATABASE [oldname] MODIFY NAME = [newname];
works without connecting to master first BUT if you are renaming a restored Azure database; don't miss the space before the final hyphen
ALTER DATABASE [oldname_2017-04-23T09 -17Z] MODIFY NAME = [newname];
And be prepared for a confusing error message in the Visual Studio 2017 Message window when executing the ALTER command
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
You can easily do it from SQL Server Management Studio, Even from the community edition.