Foreign Data Wrapper elasticsearch postgresql - postgresql

I tried to perform postgresql and Elasticsearch together using Foreign Data Wrapper. I have followed this : https://github.com/Mikulas/pg-es-fdw
When I insert new articles, everything is working but when I try to update or delete, it show me some errors :
ERROR: Cannot transform anything else than mappings andsequences to rows
État SQL :XX000
Contexte : SQL statement "DELETE FROM articles_es a WHERE a.id = OLD.id"
PL/pgSQL function delete_article() line 3 at SQL statement
Anyone could help me?
Thanks!

Related

PostgreSQL equivalent of SQL merge trigger and INSERTED table

I am new to database triggers/PostgreSQL and trying to convert the following SQL trigger to PostgreSQL.
SQL script :
CREATE TRIGGER tr_EmpMerger ON Emp INSTEAD OF INSERT
AS
BEGIN
MERGE INTO Emp AS Target
USING ( SELECT * FROM INSERTED ) AS Source
ON
( Target.EmpId = Source.EmpId
)
WHEN MATCHED THEN UPDATE SET
EmpName = Source.EmpName,
Age = Source.Age
WHEN NOT MATCHED THEN INSERT VALUES
(
Source.EmpId,
Source.EmpName,
Source.Age
);
END
GO
Questions :
1) Is there any equivalent of SQL's INSERTED table in PostgreSQL? If not, what is the work around?
2) Does PostgreSQL support Merge triggers? If not, what is the work around?
3) What will be the equivalent PostgreSQL script for the above merge trigger?
EDIT :
Note - In this scenario the insertion of data into the Emp table (as well as other tables) is happening through Bulk Copy command of Postgres. So there is no direct INSERT INTO query available for this table

execute multiple DB2 statements with MyBatis

i have searched for some posts related to executing multiple SQL statements with Mybatis. but that didnt work. i need to execute multiple DB2 statements in MyBatis . consider i have to run 3 DELETE statements
i have referred below link . in this post they have given example for Mybatis with ORACLE.
MyBatis executing multiple sql statements in one go, is that possible?
Query syntax :
<delete id="clearTable" parameterType="test">
DELETE FROM tableA WHERE key = #{key}
DELETE FROM tableb WHERE key = #{key} and param = #{param}
DELETE FROM tablec WHERE key = #{key} and param = #{param}
<delete>
error log :
Translating SQLException with SQL state '42601', error code '-199', message [[SQL0199] Keyword DELETE not expected. Valid tokens: OR USE SKIP WAIT WITH.]; SQL was [] for task [
Error updating database. Cause: java.sql.SQLException: [SQL0199] Keyword DELETE not expected. Valid tokens: OR USE SKIP WAIT WITH.
SQL: DELETE FROM tableA WHERE key = ? DELETE FROM tableb WHERE key = ? and param = ? DELETE FROM tablec WHERE key = ? and param = ?
Cause: java.sql.SQLException: [SQL0199] Keyword DELETE not expected. Valid tokens: OR USE SKIP WAIT WITH.
Thanks in Advance
MyBatis appears to expect a single line for its SQL statements. I don't use MyBatis, but I use DB2. Try either calling a stored procedure (and pass it the key-values of items to delete), or try an anonymous block.
begin atomic
DELETE FROM tableA WHERE key = 1 ;
DELETE FROM tableb WHERE key = 2 and param = 1 ;
DELETE FROM tablec WHERE key = 3 and param = 1 ;
end#
The above syntax is valid for DB2 Linux/Unix/Windows current versions (v10.5 or v11.1 ) - you would replace the literal values with the MyBatis (or whatever) parameter-markers.
One detail is that the syntax above has two delimiters, one is the statement delimiter (which in my example is #), the other is the intra-statement delimiter (which in my example is ;) and DB2 lets you configure both of these delimiters , so you might need to give at least one of those details to DB2 somehow when opening the connection from MyBatis.

Nested query as PostGIS function parameter

I have a PostGIS query where I really need to have nested queries inside PostGIS function calls:
UPDATE raw.geocoding
SET the_geom = ST_Centroid(
ST_Collect(
SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C000081610F9CC5DC3341EE672E6E723B3241')::varchar),
SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C00002CF887E0C5DC3341C9E5B2DF2A383241')::varchar)
)
)
WHERE hash = ((E'3e638a27c6c38f05026252f4a0b57b2e')::varchar)
Unfortunately, this doesn't work. I get a syntax error at the beginning of the nested query:
ERROR: syntax error at or near "SELECT"
LINE 4: SELECT the_geom
^
********** Error **********
ERROR: syntax error at or near "SELECT"
SQL state: 42601
Character: 86
Looks like I cannot have a nested query as a PostGIS function parameter?
I've perused through the PostGIS documentation and cannot find any clear guidance for dealing with this.
It appears Postgres has a way of doing variables in pgSQL, but it's unclear to me how this would be pulled off in a standard query. This is a query that will be run tens or hundreds of thousands of times from a C# program. That aside, I could do a pgSQL stored procedure if required; just wanted to make sure there wasn't a simpler alternative first.
In case you were wondering, the query looks messy because it's the result of a npgsql-generated parameterized query. I think it's fair to say that npgsql is being extra-cautious with redundant typing and escaping.
I am running PostGIS 2.0.1, Postgres 9.1.5, and npgsql 2.0.12.
It sounds like you want a scalar subquery, an expression written like (SELECT ....) (note enclosing parentheses) that contains a query returning either zero rows (NULL result) or one field from one row.
You were most of the way there, you just needed the parens:
UPDATE raw.geocoding
SET the_geom = ST_Centroid(
ST_Collect(
(SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C000081610F9CC5DC3341EE672E6E723B3241')::varchar)),
(SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C00002CF887E0C5DC3341C9E5B2DF2A383241')::varchar))
)
)
WHERE hash = ((E'3e638a27c6c38f05026252f4a0b57b2e')::varchar)
Note that subqueries can be used in other places too - table returning subqueries can appear in FROM, for example. The PostgreSQL manual teaches about all this, and is well worth a cover-to-cover read.
If you're doing a lot of these updates, you may find it more efficient to formulate the UPDATE as a join using the PostgreSQL extension UPDATE ... FROM ... WHERE rather than running lots of individual UPDATEs over and over. I just wanted to raise the possibility. See from-list in UPDATE

DB2 compound statement using ADO.NET

I want to execute multiple statements from my data access layer using C# dan IBM's DB2 data provider.
(environment: DB2/AS400 os version: V5R4)
eg in TSQL:
declare varA integer;
select varA= count(*) from tableA;
select * from tableB where col1 <= varA
with SQL server ; I can concatenate those 3 statements into a string
and assign the text to DBCommand.CommandText.
How to execute multiple statements(compound statement) against DB2 database via DBCommand (using IBM DB2 data provider)
I tried using begin and end block but still failed
BEGIN
statement1;
statement2;
statement3;
END
Thank you
I do not think it's possible.
I had already tried something similar some time ago, and the only solution I found is to dynamically create a stored procedure, calling it, and finally delete it.

TSQL SQL 2000 stored proc cursor

I'm new to this board. I have been driving myself crazy trying to find the answer to my problem.
I created some TSQL code that executes some dynamic SQL in a cursor within a stored proc. The cursor fetches some data from table x, builds a query based data retrieved in table x, runs the query, and returns data. Works like a charm.
When I add an 'insert into table' to capture the results I get an error: NOTE: only errors with SQL 2000 runs great on SQL 2008.
The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].
You should not be using a cursor for this. My guess would be a comflict with the cursor and the insert into table.
Please post code and the problem you are tyring to solve so that we can help you write it correctly.