error when running anonymous block - postgresql

running into the below error when trying to run a simple anonymous block
do $$ begin raise notice 'Hello, World!'; end $$;
error
Describe Error: Failed to retrieve EXPLAIN plan(s): ERROR: syntax
error at or near "do"
DB is PostgreSQL 9.1.18 on x86_64-unknown-linux-gnu
any ideas on what is going wrong?
I am using aqua data studio and pgadmin and get the same error

Related

SQL Error [42601]: ERROR: syntax error at the filepath while importing csv file in postgresql

I have created an table and then I'm trying to import a csv file from my local machine. I wrote on the console in the following way.
copy schema_name.newtble (col_1, col_2, col_3, ID) FROM ‘D:\directory\subderictory\filename.csv’ DELIMITER ‘,’ CSV HEADER;
But I got the error
SQL Error [42601]: ERROR: syntax error at or near "‘D"
Please help me to solve it out. It seems like I have done some silly mistake.

bucardo sync issue, function does not exist

I have issues with adding database to sync. DB versions: PostgreSQL 9.6.8 (RDS), Jump system: Ubuntu18.04 LTS, bucardo version: 5.4.1.
When trying run this command:
bucardo add sync db_sync relgroup=copying_herd dbs=source_db:source,dest_db:target onetimecopy=1
I receive this error:
WARNING: Issuing rollback() due to DESTROY without explicit disconnect() of DBD::Pg::db handle dbname=dc_sourcedb;host=xxx.aaa.xyz;port=5432 at line 126.
Failed to add sync: DBD::Pg::st execute failed: ERROR: DBD::Pg::db do failed: ERROR: function search_string(text) does not exist
LINE 5: array_agg(search_string(x)),
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY:
SELECT
coalesce(
array_to_string(
array_agg(search_string(x)),
'|'
)::text,
''
)
FROM unnest($1) x
CONTEXT: SQL function "flatten_text_array" during inlining at line 126. at line 30.
CONTEXT: PL/Perl function "validate_sync" at /usr/bin/bucardo line 4612.
Function search_string exist and I can run this function from psql command line

BigSQL PostgreSQL CREATE EXTENSION errors

I have windows 8.1 and I want to try hadoop_fdw. Problem is with loading the extension with:
CREATE EXTENSION hadoop_fdw;
ddssdg
ERROR: could not load library "D:/PROGRA~2/POSTGR~2/pg95/../pg95/lib/postgresql/hadoop_fdw.dll": unknown error 126
********** Error **********
ERROR: could not load library "D:/PROGRA~2/POSTGR~2/pg95/../pg95/lib/postgresql/hadoop_fdw.dll": unknown error 126
SQL state: XX000
I tried to create extension manually from SQL located at "D:\Program Files\PostgreSQLBigsql\pg95\share\postgresql\extension"
CREATE FUNCTION hadoop_fdw_handler()
RETURNS fdw_handler
AS 'D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll'
LANGUAGE C STRICT;
CREATE FUNCTION hadoop_fdw_validator(text[], oid)
RETURNS void
AS 'D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll'
LANGUAGE C STRICT;
CREATE FOREIGN DATA WRAPPER hadoop_fdw
HANDLER hadoop_fdw_handler
VALIDATOR hadoop_fdw_validator;
I get this error same error again:
ERROR: could not load library "D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll": unknown error 126
********** Error **********
ERROR: could not load library "D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll": unknown error 126
SQL state: XX000
What I am doing wrong?
EDIT 1: So I found missing DLL's. They are:
API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL
API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL
JVM.DLL
I added them to C:\Windows\SysWOW64\ and extension still doesn't work - it probably requires restart.

PostgreSQL plperlu compilation error: ERROR: didn't get a CODE reference from compiling function

I have created language plperlu in Postgres 9.3 (OS - UBUNTU 12.04.5), using below command
CREATE LANGUAGE plperlu;
I wanted to call shell script from postgres function So I written below function using plperlu.
Below is function
CREATE OR REPLACE FUNCTION tet_func (integer) RETURNS boolean
AS $$
$checkexitcode = system
("sh test_shell.sh");
if ($checkexitcode > 0) { return false; }
return true;
$$ LANGUAGE plperlu;
While compiling I am getting below error
ERROR: didn't get a CODE reference from compiling function "tet_func"
CONTEXT: compilation of PL/Perl function "tet_func"
********** Error **********
ERROR: didn't get a CODE reference from compiling function "tet_func"
SQL state: XX000
Context: compilation of PL/Perl function "tet_func"
Does anybody have idea why this error is occurring? Or anyone has other solution to call shell script from postgres function.

Return error number

I want to return error number using PostgreSQL 9.3 Version.
I referred this :-> http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html
but want to know how do I return the error number.
In SQL Server 2008 R2 we just use ##ERROR..
Example:
IF ##ERROR <> 0
BEGIN
PRINT 'Error message';
RETURN(1);
END
My Question: Can we get error number in PostgreSQL like we get in SQL Server by using ##ERROR?
In PL/pgSQL, you must trap errors and you can raise (custom) errors. (Normal execution is stopped during an error.)
Errors in PostgreSQL has levels, error codes (SQLSTATE) and explicit names.
F.ex:
BEGIN
-- code that can potentially raise an error
EXCEPTION
WHEN division_by_zero THEN -- trap by name
-- handle division_by_zero
WHEN SQLSTATE '22012' THEN -- trap by SQLSTATE
-- handle SQLSTATE 22012
WHEN OTHERS THEN -- trap all other error
RAISE no_data; -- raise error by name
RAISE SQLSTATE '02000'; -- raise error by SQLSTATE
END