Procedure is not getting created in postgres11 - pgadmin-4

I am getting below error while creating simple stored procedure in postgresql-11,
ERROR: syntax error at or near "create"
LINE 4: create or replace procedure transfer(
How to solve this error?
See the screenshot for more info.

As ran in the query tool got few syntax errors after rewriting as below executed successfully:
create or replace procedure transfer()
language plpgsql
as $$
DECLARE
begin
Select now();
END $$;

Related

Snowflake How to execute remove file in stage through a stored procedure?

How to execute rm #mystage/data/input/ pattern='.*success.*'; from a stored proc
I'm getting an error message "Stored procedure execution error: Unsupported statement type 'UNKNOWN'."
The following procedure works for me
CREATE OR REPLACE PROCEDURE RM_FROM_STAGE() RETURNS STRING LANGUAGE JAVASCRIPT AS
$$ snowflake.execute({sqlText: `rm #mystage/test/ pattern='.*success.*'` }); $$;
Maybe all you need are the backquotes...

System.Data.SqlClient.SqlException procedure has no parameters and arguments were supplied. How should I go about fixing this error?

I built a database application in Visual Studio. When I run, I get this error:
System.Data.SqlClient.SqlException: procedure sp_select_number_of_films has no parameters and arguments were supplied.
I know what the error means, but I am not sure how to fix it in my SQL code. I have tried a bunch of small tweaks, but I still get the same error.
Stored procedure:
CREATE PROCEDURE [dbo].[sp_select_number_of_films]
(#REC_ID_OUTPUT int OUTPUT)
AS
SELECT COUNT(*)
FROM Film.Title;
EXEC dbo.sp_select_number_of_films
GO
It should be called as:
DECLARE #sth INT;
Exec dbo.sp_select_number_of_films #sth OUTPUT;
But then inside stored procedure you need to assign output variable:
CREATE PROCEDURE [dbo].[sp_select_number_of_films]( #REC_ID_OUTPUT int OUTPUT)
AS SELECT #REC_ID_OUTPUT = COUNT(*)
FROM Film.Title;
And you should avoid naming stored procedures with "sp_" prefix.

Creating Procedures with Transactions using PGAdmin 4

I'm coming from a long history with SQL Server and trying to learn PL/PGSQL. I've recently discovered the PG11 feature CREATE PROCEDURE which allows for internal transactions inside their body.
As a learning exercise, I've created this:
DROP PROCEDURE IF EXISTS test_proc();
CREATE PROCEDURE test_proc()
LANGUAGE plpgsql
AS $$
BEGIN
DROP TABLE IF EXISTS a;
CREATE TABLE a (aid int);
COMMIT;
END;
$$;
call test_proc();
It works fine in PSQL, however when I execute it in PGAdmin 4's Query Tool, it errors with
ERROR: invalid transaction termination
CONTEXT: PL/pgSQL function test_proc() line 5 at COMMIT
SQL state: 2D000
Can someone please explain what's going on? I'm guessing that the PROCEDURE is in fact valid and the issue might be in the query tool might be incorrectly processing the contained COMMIT.
Are there any suggestions for working around this?
Thanks!
In Pgadmin CREATE PROCEDURE as FUNCTION
please try this by Replace PROCEDURE with Function and add Return type also and it will work
DROP FUNCTION IF EXISTS test_proc();
CREATE FUNCTION test_proc()
RETURNS VOID
LANGUAGE plpgsql
AS $$
BEGIN
DROP TABLE IF EXISTS a;
CREATE TABLE a (aid int);
COMMIT;
END;
$$;
Can you please try unchecking auto commit & auto rollback options in pgAdmin4?
You can find drop down near Execute button in the query tool.

Error when trying to execute stored procedure

When trying to run a stored procedure, I get the following error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '#CSVPath'.
I'm trying to execute it using the following:
EXEC dbo.ProcessData #CSVPath = 'D:\Data.csv'
My stored procedure starts like this:
ALTER PROCEDURE [dbo].[ProcessDataData]
#CSVPath varchar(MAX) --Path to CSV containing data.
AS
BEGIN
{query}
END
I don't know what I'm doing wrong when passing the parameter value.
Thank you.
Assuming Your proc name has the word data only once, I have just managed this successfully:
create PROCEDURE [dbo].[ProcessData]
#CSVPath varchar(MAX) --Path to CSV containing data. AS BEGIN
select #CSVPath END
EXEC dbo.ProcessData #CSVPath = 'D:\Data.csv'
Output:
D:\Data.csv
First confirm with stored procedure name and use the same SP name so that u will not get this kind of errors
You are executing wrong sp
use below query it will execute
EXEC dbo.ProcessDataData #CSVPath = 'D:\Data.csv'
This is work...your Procedure name is [dbo].[ProcessDataData] and you execute EXEC dbo.ProcessData....please like that execute EXEC dbo.ProcessDataData its work for mee...
ALTER PROCEDURE [dbo].[ProcessDataData]
#CSVPath varchar(MAX) --Path to CSV containing data.
AS
BEGIN
-- Query to execute data
END
EXEC dbo.ProcessDataData #CSVPath = 'D:\Data.csv'
Hope Its Work !!!
Happy Coding !!!
Try it, may be it works for you;
EXEC dbo.ProcessData 'D:\Data.csv'
It'll auto map your data to the parameter: #CSVPath. Otherwise, may be the issue was in your query. If issue still exists, share your complete StoredProcedure for better judgment and solution.

Getting error Incorrect syntax near the keyword 'BEGIN' when executing stored procedure

So, I'm new to MS SQL (have been using oracle for the last 5-7 years) and this should be very a straight forward thing to do, so I reckon I'm missing something very simple.
(I've tried following the examples here: http://technet.microsoft.com/en-us/library/ms190669(v=SQL.105).aspx)
So, I create the following stored procedure to query a table (this is a very simple and pointless procedure but I can't proceed with my more complex procedure until I resolve this problem)
create procedure sp_getTransactions
as
select * from MyTransactions;
I then try to execute this procedure
execute dbo.sp_getTransactions
(I've tried without the dbo. and get the same error)
This gives me the very helpful error
Incorrect syntax near the keyword 'BEGIN'.
Now, maybe I'm crazy but I don't see a begin statement anywhere in my procedure (I've tried adding one to no avail).
Can anyone give me some pointers here?
Thanks
Actually, the problem as it turns out is the client I was using. I was executing the sql scripts using Oracle's SQLDeveloper with the MSSQL jTDS driver. It seems this driver works fine for the most part, but when it comes to running stored procedures there's a bug.
I guess the execute statement isn't parsed properly by the plugin when being set to the server
Check like this:
CREATE PROCEDURE sp_getTransactions
AS
BEGIN
SELECT * FROM MyTransactions;
END
In execute dbo.sp__getTransactions statement, you used 2 _, but in CREATE PROCEDURE statement it has only one. Change to dbo.sp_getTransactions and try to execute.

Resources