Postgresql Insert into server from local using dblink - postgresql

I am connecting postgres in 192.168.4.12 I want to insert into table in server IP 192.168.4.13, I have tried but I get error.
ERROR: syntax error at end of input
CONTEXT: Error occurred on dblink connection named "unnamed": could not execute command.
********** Error **********
ERROR: syntax error at end of input
SQL state: 42601
Context: Error occurred on dblink connection named "unnamed": could not execute command.
Here is the syntax.
SELECT dblink_exec
('hostaddr=192.168.4.13 dbname=mrp-pti-coba user=postgres password=passwordb',
'insert into mst_item(item_id) values
(dblink_exec("hostaddr=192.168.4.12 dbname=mrp-exp2 user=postgres password=passworda","select item_id from mst_item")');

Related

PostgreSQL copy issues

I am trying to copy my PostgreSQL query result set into an excel file since Tableau Public does not connect to PostgreSQL.
I am unsure how to get my result set into excel. I've been watching countless YouTube vids and read numerous stack overflow & postgresql threads to no avail. I am using postgresql 14 on pgadmin on a Mac. Appreciate any response!
The code below is what I tried and I get this error message:
copy (select * from emp) to '/Users/my_name/Desktop/sql_query.csv' with csv
ERROR: could not open file "/Users/my_name/Desktop/sql_query.csv" for writing: Permission denied
HINT: COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.
SQL state: 42501
I also tried \copy and got this error message:
ERROR: syntax error at or near "\"
LINE 1: \copy (select * from emp) to '/Users/my_name/Desktop/sq...
^
SQL state: 42601
Character: 1

How to create procedure in PostgreSQL

I'm trying to convert Oracle to PostgreSQL. I'm getting error like ERROR: syntax error at or near "UPDATE_USER_PWD_INVALID1" while creating procedure
CALL PROCEDURE UPDATE_USER_PWD_INVALID1 IS
-- PRAGMA AUTONOMOUS_TRANSACTION;
V_INVALID_COUNT USERSMPININVALID.INVALID_COUNT%TYPE;

DB2 encrypt field in select statement

So I need to do a select statement, while encrypting a field in SHA2_512. I'm not sure which DB2 version it is, but I tried both queries and neither work.
When trying this query:
SELECT HEX(HASH_SHA256('ABCDEFGHIJKLMNOPQRZTUVWXYZ'))
FROM SYSIBM.SYSDUMMY1;
I get the following error:
Error: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884,
SQLERRMC=FUNCTION;HASH_SHA256, DRIVER=3.71.22 SQLState: 42884
ErrorCode: -440 Error: DB2 SQL Error: SQLCODE=-514, SQLSTATE=26501,
SQLERRMC=SQL_CURLH200C1, DRIVER=3.71.22 SQLState: 26501 ErrorCode:
-514
While with this query
SELECT hash('Charlie at IBM', 3)
FROM SYSIBM.SYSDUMMYU;
Error: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884,
SQLERRMC=FUNCTION;HASH, DRIVER=3.71.22 SQLState: 42884 ErrorCode:
-440 Error: DB2 SQL Error: SQLCODE=-514, SQLSTATE=26501, SQLERRMC=SQL_CURLH200C1, DRIVER=3.71.22 SQLState: 26501 ErrorCode:
-514
(while without the hash functions the query runs without any issues). Anyone know how I can fix this issue?
I'm not sure which DB2 version I'm using but by using these queries I get these results:
SELECT GETVARIABLE('SYSIBM.VERSION') FROM SYSIBM.SYSDUMMY1
DSN11015
select GETVARIABLE('SYSIBM.NEWFUN') AS COMPATIBILITY from sysibm.sysdummy1
COMPATIBILITY: V11
https://www.ibm.com/docs/en/db2/11.1?topic=functions-hash
https://www.ibm.com/docs/en/db2-for-zos/12?topic=sf-hash-crc32-hash-md5-hash-sha1-hash-sha256
You appear to be using Db2-v11 for Z/OS "DSN11015" in V11 compatibility mode.
This version lacks the scalar function HASH_SHA256 (and others) which is present in Db2-v12 for z/OS. That is the reason you get sqlcode -440 (no such function HASH...) with your Db2-for-z/os version.
At Version-11 , IBM documents a function ENCRYPT_TDES which may help you.
Background information on using this function.
You can write your own functions if you have the skills.

ERROR: syntax error at or near "ALL" postgres GRANT psql 8.4.15

I have a postgresql version 8.4.15 database and when I want to give a user permissions on tables, I get a syntax error that in postgres version 11.5 it doesn't.
ERROR: syntax error at or near "ALL"
LINE 1: GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO consulta;
ERROR: syntax error at or near "ALL"
LINE 1: GRANT SELECT ON ALL TABLES IN SCHEMA public TO consulta;

iReport Designer: permission denied for relation

I didn't face this error before. I have a database db, that contains a table tb_name, I create a connection in iReport Designer with credentials of the db owner. Then I create new report, but the query select * from tb_name; throws the following error:
SQL problems: ERROR: permission denied for relation tb_name
Query error
Message:
net.sf.jasperreports.engine.JRException: SQL problems: ERROR: permission denied for relation tb_name Level:
SEVERE Stack Trace: SQL problems: ERROR: permission denied for relation tb_name
com.jaspersoft.ireport.designer.data.fieldsproviders.SQLFieldsProvider.getFields(SQLFieldsProvider.java:435)
com.jaspersoft.ireport.designer.connection.JDBCConnection.readFields(JDBCConnection.java:470)
com.jaspersoft.ireport.designer.wizards.ConnectionSelectionWizardPanel.validate(ConnectionSelectionWizardPanel.java:146)
org.openide.WizardDescriptor$7.run(WizardDescriptor.java:1357)
org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
When I test connection everything's fine. What can be a reason of this error? Thanks in advance.
Please check if the user has rights to execute statements. Some database changes might have caused the user to lose query permission.