I'm using EF6 with Oracle ODP.Net and Code First migration in my app.
When i run
Update-Database
I'm getting:
Oracle.ManagedDataAccess.Client.OracleException (0x00001996): ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
but when i run
Update-Database -script
The generated script works fine on my database. After trying
Update-Database -verbose
I found that the is a difference in scripts generated by 'Update-Database -verbose'
begin
execute immediate
'create index "SYS_MZK"."IX_REALIZACJE_KURSOW_R_6940446" on "SYS_MZK"."REALIZACJE_KURSOW" ("RLK_FK_KUR_ID")';
exception
when others then
if sqlcode <> -1408 then
raise;
end if;
end;
begin
execute immediate
'create index "SYS_MZK"."IX_REALIZACJE_KURSO_1395326627" on "SYS_MZK"."REALIZACJE_KURSOW" ("RLK_FK_PNM_ID_AKT_POL")';
exception
when others then
if sqlcode <> -1408 then
raise;
end if;
end;
and 'Update-Database -script":
begin
execute immediate
'create index "SYS_MZK"."IX_REALIZACJE_KURSOW_R_6940446" on "SYS_MZK"."REALIZACJE_KURSOW" ("RLK_FK_KUR_ID")';
exception
when others then
if sqlcode <> -1408 then
raise;
end if;
end;
/
begin
execute immediate
'create index "SYS_MZK"."IX_REALIZACJE_KURSO_1395326627" on "SYS_MZK"."REALIZACJE_KURSOW" ("RLK_FK_PNM_ID_AKT_POL")';
exception
when others then
if sqlcode <> -1408 then
raise;
end if;
end;
/
The dissapearing of '/' is my problem - is there a way to change the way of generating above script
Related
I got this error while trying to run docker-compose up --build, I'm using postgresql as my database service. I think there's wrong with my query.When i remove the CREATE TRIGGER it somehow run without erros.
LINE 13: CREATE TRIGGER update_communication
backend-postgres-1 |^
Here is my sql file
CREATE OR REPLACE FUNCTION dts.save_communication_revision()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$$
BEGIN
INSERT INTO dts.communication_revisions(com_id, class_id, com_subject, user_id, com_source_name, "com_dateCreated", "com_dateReceived", com_urgency, com_source_position, com_source_office, com_draft, com_other_remarks, "com_controlNo", com_due_date)
VALUES(OLD.com_id, OLD.class_id, OLD.com_subject, OLD.user_id, OLD.com_source_name, OLD."com_dateCreated", OLD."com_dateReceived", OLD.com_urgency, OLD.com_source_position, OLD.com_source_office, OLD.com_draft, OLD.com_other_remarks, OLD."com_controlNo", OLD.com_due_date);
END;
$$
CREATE TRIGGER update_communication
AFTER UPDATE
ON dts.communications
FOR EACH ROW
EXECUTE PROCEDURE dts.save_communication_revision();
END;
$$;
Just added this semicolon.
I'm trying without success to create a function in Postgres that save a table or database taking one or two parameters. In this case I was trying to create it with only one parameter(name of the table or database) and backup this table/db
--SELECT backup_table(sports)
CREATE FUNCTION backup_table(TEXT) RETURNS BOOLEAN AS
$$
DECLARE
table_x ALIAS FOR $1;
BEGIN
COPY table_x FROM 'C:/path/backup_db' WITH (FORMAT CSV);
RAISE NOTICE 'Saved correctly the table %',$1;
RETURN BOOLEAN;
END;
$$ LANGUAGE plpgsql;
I've always receive the error when I try to execute the function SELECT backup_table(sports):
"The column sports doesnt exists."
SQL state: 42703
Character: 21
The idea is to create the function like the equivalent of SQL Server BACKUP DATABASE TO DISK, or equivalent to pg_dump command
pg_dump -U -W -F t sports > C:/path/backup_db;
I know about SQL but now I'm just stuck with this error.
I am trying to run a for loop via psql command in Linux to do some spatial operations in PostGIS database
My SQL command which I successfully ran in dbeaver looks something like this
DO $$
declare
the_name varchar(50);
BEGIN
FOR the_name IN
SELECT "name" FROM myschema.mytable WHERE "idcolumn" = 'selected id' LIMIT 4
LOOP
some operations inside the loop...
END LOOP;
RAISE NOTICE 'the name - (%)', the_name;
END;
$$;
I usually copy-paste the dbeaver SQL command inside psql -c and it runs fine. But I am getting a syntax error when using the above code. I am a beginner in SQL and any help is appreciated. Thanks.
Edit
This is the error message - it's weird because I don't have this number in the code. It's probably reading from memory or something.
ERROR: syntax error at or near "377643"
LINE 1: DO 377643 declare the_name varchar(50); BEGIN FOR the_...
I have the following code:
DROP TABLE IF EXISTS pltest;
CREATE TABLE pltest (x jsonb);
DO $$
DECLARE startdate text := to_char(current_date - 1, 'YYYYMMDD');
BEGIN
EXECUTE format(
'COPY pltest FROM PROGRAM ''curl "https://example.com/events/start_date=%sT000000Z"''',
startdate
);
END
$$ ;
It basically imports the URL with a parameterized COPY statement so it always imports the data of the last 24 hours, it runs perfectly in SQL shell, but when i tried adding a pgagent job with that code, pgagent returns "syntax error near DECLARE".
PostgreSQL version: 13.3
PgAgent version: 13
This code looks correct. It fails with expected error.
ERROR: invalid input syntax for type json
DETAIL: Token "<" is invalid.
CONTEXT: JSON data, line 1: <...
COPY pltest, line 1, column x: "<!doctype html>"
SQL statement "COPY pltest FROM PROGRAM 'curl "https://example.com/events /start_date=20210526T000000Z"'"
PL/pgSQL function inline_code_block line 5 at EXECUTE
Maybe your client breaks source code, or maybe your Postgres is too old.
I'm setting up an AFTER INSERT trigger to launch an SSA job which executes a SSIS package to report on an ETL log file after its process completes. The syntax for the TRY...CATCH block appears correct but the error handling doesn't work for the error code when it detects the SSA job it's told to launch is already running.
The trigger is for a user table in a SQL Server 2012 SP4 instance (with SQL 2012 (110) compatibility). I tried handling the one error (#22022) for a SQL job already running but it seems that you can't error trap the execution of a system stored procedure.
CREATE TRIGGER InterfaceSupport.trg_XMLTrigger_Insert
ON [InterfaceSupport].[XMLLogReaderTriggers]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
EXEC msdb.dbo.sp_start_job 'Launch job'
END TRY
BEGIN CATCH
IF ERROR_NUMBER()=22022 --Job already running
EXEC msdb.dbo.sp_send_dbmail NULL,'name#domain.org',NULL,NULL,'Interface XML Log Reader Already Running','The SSA Job reading Interface logs is already running. The job will attempt to catch the new request at the end of the current cycle.'
ELSE
BEGIN
DECLARE #Errormsg nvarchar(max)
SELECT #Errormsg=ERROR_MESSAGE()
EXEC msdb.dbo.sp_send_dbmail NULL,'name#domain.org',NULL,NULL,'Interface XML Log Reader Spawn Error',#Errormsg
END
END CATCH
END
GO
I'm getting the following error despite the error handling block. It's as if the CATCH block is non-existent.
Msg 22022, LeveSQLServerAgent Error: Request to run job Launch Job (from User xxx) refused because the job is already running from a request by User xxx. l 16, State 1, Line 17
This error can't be caught by TRY/CATCH unfortunately.
You should check if the job is running and start only if it's not, although the job might start in between the check and the EXEC statement.
DECLARE #JobID UNIQUEIDENTIFIER = (SELECT job_id FROM msdb.dbo.sysjobs AS J WHERE J.name = 'Launch job')
IF NOT EXISTS (
SELECT
'job is running'
FROM
msdb.dbo.sysjobactivity ja
INNER JOIN msdb.dbo.sysjobs j ON ja.job_id = j.job_id
WHERE
ja.session_id = (SELECT TOP 1 session_id FROM msdb.dbo.syssessions ORDER BY agent_start_date DESC) AND
ja.start_execution_date is not null AND
ja.stop_execution_date is null AND
ja.job_id = #JobID
)
BEGIN
EXEC msdb.dbo.sp_start_job #job_name = 'Launch job'
END
ELSE
BEGIN
EXEC msdb.dbo.sp_send_dbmail NULL,'name#domain.org',NULL,NULL,'Interface XML Log Reader Already Running','The SSA Job reading Interface logs is already running. The job will attempt to catch the new request at the end of the current cycle.'
END