I am trying to execute a function dev.dev_support_process in a different database of same instance using the dblink
select
*
from
dblink('port=5432 dbname=dev host=postgres.database.azure.com user=dev#pgsql-dev-db password=dev123' ,
'SELECT * FROM dev.dev_support_process ( ''support'' )');
Also tried the same command with dblink_exec.
Getting the same error from the functions exceptional part. Can anyone help me on this.
Postgres version 11.4
I tried but getting below error.
ERROR: function dev_support_log_message(character varying, unknown) does not exist HINT: No function matches the given name and argument types. You might need to add explicit type casts. CONTEXT: while executing command on unnamed dblink connection PL/pgSQL function dev.dev_support_process(text) line 26 at PERFORM
dev_support_log_message is the function called inside the dev_support_process as a exception part.
I verified the user is having access to execute the function and can execute manually. I am getting the error only when I am trying from this dblink.
Thanks in advance.
Related
Trying to create trigger which is supposed to use NEW and OLD and also accept table name as param, but always getting error:
You cannot directly call a trigger function from SQL or PL/pgSQL. So this line is wrong
EXECUTE function_update(table_name );
for three reasons:
EXECUTE takes a string containing an SQL function as argument. So PostgreSQL wants to call your function and execute the result as an SQL statement. You mean PERFORM function_update(table_name);, but that is also wrong for the following reasons.
You supply an argument to the function, but you defined it without parameters. This causes the error message.
You are trying to call a trigger function in an SQL statement. That will always fail.
You shouldn't have defined function_update as trigger function, but as normal function that can be called from SQL.
I'm trying to query records from a table resides in different dababase on the same host using dblink in psql tool, but getting this error
database1=# SELECT * FROM dblink('database2', 'SELECT id FROM users');
ERROR: function dblink(unknown, unknown) does not exist
LINE 1: SELECT * FROM dblink('database2', 'SELECT id FROM ...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
can somebody help , how can we do cross database query in psql
I've created a function in a database that inserts records into a table. This function returns VOID and takes a VARIADIC text array as an input param. When I run the function from the database locally, it works fine, as expected.
But when I try to run from a different database, using a foreign data wrapper it will not work, throws different errors depending on the method I use.
Here's how I make one kind of call:
SELECT dblink('pg_log',
'SELECT public.insert_log(''usage'', ''txn'', ''dimensions'', ''test'', null,
''pgwrapper'', ''temp_var'', null, null, null, ''Start'', null,
null, null, null);');
That one throws this error:
function returning record called in context that cannot accept type record
When I replace Select dblink with PERFORM dblink, I get this error:
syntax error at or near "PERFORM"
And when I try, SELECT dblink_exec:
I get this error:
statement returning results not allowed
Again, the function works as I have called it locally to test it and it does what it should.
I checked the connection with this and it return OK:
SELECT dblink_connect('pg_log');
Anyone have any ideas why this is failing and suggestions on fixing?
Thanks!
It looks like you need to try SELECT * FROM dblink(...) AS t1(column_name type) instead of SELECT dblink(...).
From the PostgresSQL Documenation:
The function returns the row(s) produced by the query. Since dblink can be used with any query, it is declared to return record, rather than specifying any particular set of columns. This means that you must specify the expected set of columns in the calling query — otherwise PostgreSQL would not know what to expect. Here is an example:
SELECT *
FROM dblink('dbname=mydb options=-csearch_path=',
'select proname, prosrc from pg_proc')
AS t1(proname name, prosrc text)
WHERE proname LIKE 'bytea%';
We have connected redshift DB in sql-workbench/aginity. I am able to create function but I couldn't EXECUTE that created function in workbench. Below is the sample syntax we tried to call the function.
execute public.test_function
execute test_function
By the way, is the correct syntax to execute a function?
As documented in the manual execute is used to run a prepared statement - not a function.
To "execute" a function, call it with a select statement:
select test_function();
This is my code: I trying to create UDF function for z/os from Data Studio . I don't need to use External function or others. I need to execute this SQL Function .
CREATE FUNCTION FUNCTION5()
RETURNS FLOAT
language sql
DETERMINISTIC
READS SQL DATA
NO EXTERNAL ACTION
BEGIN
DECLARE RANVAL FLOAT ;
SELECT RAND() INTO RANVAL FROM SYSIBM.SYSDUMMY1;
RETURN RANVAL ;
END
But, while executing the above code, i'm getting this error. Can yuou please help me to figure it out please.
I want to develop nearly 20 Scalar UDF on DB2 Z/OS . kindly help me, please.
Deploy [MeDB]MeDB.FUNCTION5
Running
MeDB.FUNCTION5 - Deploy started.
Create user-defined function returns SQLCODE: -199, SQLSTATE: 42601.
MeDB.FUNCTION5: 0: DB2 SQL Error: SQLCODE=-199, SQLSTATE=42601, SQLERRMC=DECLARE;ON AFTER <INTEGER>, DRIVER=4.18.60
DB2 SQL Error: SQLCODE=-199, SQLSTATE=42601, SQLERRMC=DECLARE;ON AFTER <INTEGER>, DRIVER=4.18.60
MeDB.FUNCTION5 - Deploy failed.
MeDB.FUNCTION5 - Roll back completed successfully.
I believe the function you're trying to create is not supported in DB2 7. The usage of the BEGIN, END, and DECLARE keywords indicate you're trying to use SQLPL, which isn't supported until DB2 10 as compiled scalar functions. I don't have any documentation for 7, but I think you can only create inline scalar functions, which is limited to one expression in a RETURN statement as described in the DB2 10 reference for CREATE FUNCTION (inline scalar):
The CREATE FUNCTION (inlined SQL scalar) statement defines an SQL scalar function at the current server and specifies an SQL procedural language RETURN statement for the body of the function. The function returns a single value each time it is invoked.
SQL-routine-body
Specifies a single RETURN statement.