You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem Description: PGSync does not update Elasticsearch index if a new row is added to the root table defined in schema.json if it is joined with a child table with the same name from a different schema. Below is a minimal working example.
Populate database:
BEGIN;
CREATESCHEMAIF NOT EXISTS book;
CREATESCHEMAIF NOT EXISTS author;
DO
$$
BEGIN
IF NOT EXISTS (SELECTFROMpg_catalog.pg_tablesWHERE schemaname ='book'AND tablename ='my_table') THEN
CREATETABLEbook.my_table
(
id SERIALPRIMARY KEY,
title TEXT,
author_id INTEGER
);
END IF;
END
$$;
DO
$$
BEGIN
IF NOT EXISTS (SELECTFROMpg_catalog.pg_tablesWHERE schemaname ='author'AND tablename ='my_table') THEN
CREATETABLEauthor.my_table
(
id INTEGERPRIMARY KEY,
name TEXT
);
END IF;
END
$$;
INSERT INTObook.my_table (title, author_id) VALUES ('The Great Gatsby', 1);
INSERT INTObook.my_table (title, author_id) VALUES ('The Catcher in the Rye', 2);
INSERT INTOauthor.my_table (id, name) VALUES (1, 'F. Scott Fitzgerald');
INSERT INTOauthor.my_table (id, name) VALUES (2, 'J.D. Salinger');
COMMIT;
All rows are synced as expected. Then run the following SQL to insert one more row in the books.my_table:
INSERT INTObook.my_table (title, author_id) VALUES ('Test book 1', 1);
PGSync detects the change, but does not update Elasticsearch.
Error Message (if any): There is no error message, but the verbose output from PGSync looks like this:
child._subquery:
LATERAL
(SELECT CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_1)s, CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_2)s, JSON_BUILD_ARRAY(my_table_1.id)) AS JSONB)) AS JSONB) AS _keys,
CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_3)s, my_table_1.id, %(JSON_BUILD_OBJECT_4)s, my_table_1.name) AS JSONB) AS my_table,
my_table_1.id
FROM author.my_table AS my_table_1,
book.my_table AS my_table_2
WHERE my_table_1.id = my_table_2.author_id
AND my_table_1.id = %(id_1)s)
-------------------------------------------------------------------------------
Query:
SELECT JSON_BUILD_ARRAY(anon_1._keys) AS "JSON_BUILD_ARRAY_1",
CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_2)s, my_table_1.id, %(JSON_BUILD_OBJECT_3)s, my_table_1.title, %(JSON_BUILD_OBJECT_4)s, anon_1.my_table) AS JSONB) AS "JSON_BUILD_OBJECT_1",
my_table_1.id
FROM book.my_table AS my_table_1
JOIN LATERAL
(SELECT CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_5)s, CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_6)s, JSON_BUILD_ARRAY(my_table_2.id)) AS JSONB)) AS JSONB) AS _keys,
CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_7)s, my_table_2.id, %(JSON_BUILD_OBJECT_8)s, my_table_2.name) AS JSONB) AS my_table,
my_table_2.id AS id
FROM author.my_table AS my_table_2
WHERE my_table_2.id = my_table_1.author_id
AND my_table_2.id = %(id_1)s) AS anon_1 ON anon_1.id = my_table_1.author_id
WHERE my_table_1.id = %(id_2)s
-------------------------------------------------------------------------------
txid_current:
SELECT *
FROM TXID_CURRENT()
-------------------------------------------------------------------------------
If I rename the tables to "book" and "author", still keeping them in separate schemas, root node table changes are successfully synced and the verbose output from PGSync is the following:
Query:
SELECT JSON_BUILD_ARRAY(anon_1._keys) AS "JSON_BUILD_ARRAY_1",
CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_2)s, book_1.id, %(JSON_BUILD_OBJECT_3)s, book_1.title, %(JSON_BUILD_OBJECT_4)s, anon_1.author) AS JSONB) AS "JSON_BUILD_OBJECT_1",
book_1.id
FROM book.book AS book_1
LEFT OUTER JOIN LATERAL
(SELECT CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_5)s, CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_6)s, JSON_BUILD_ARRAY(author_1.id)) AS JSONB)) AS JSONB) AS _keys,
CAST(JSON_BUILD_OBJECT(%(JSON_BUILD_OBJECT_7)s, author_1.id, %(JSON_BUILD_OBJECT_8)s, author_1.name) AS JSONB) AS author,
author_1.id AS id
FROM author.author AS author_1
WHERE author_1.id = book_1.author_id) AS anon_1 ON anon_1.id = book_1.author_id
WHERE book_1.id = %(id_1)s
-------------------------------------------------------------------------------
1)
pkeys: [3]
{'_meta': {'author': {'id': [1]}},
'author': {'id': 1, 'name': 'F. Scott Fitzgerald'},
'id': 3,
'title': 'Test book 1'}
----------
txid_current:
SELECT *
FROM TXID_CURRENT()
-------------------------------------------------------------------------------
The text was updated successfully, but these errors were encountered:
PGSync version: 3.1.0
Postgres version: 13
Elasticsearch/OpenSearch version: 8.13.4
Redis version: 7.2.5
Python version: 3.12
Problem Description: PGSync does not update Elasticsearch index if a new row is added to the root table defined in schema.json if it is joined with a child table with the same name from a different schema. Below is a minimal working example.
Populate database:
Then start PGSync with the following schema.json:
All rows are synced as expected. Then run the following SQL to insert one more row in the books.my_table:
PGSync detects the change, but does not update Elasticsearch.
Error Message (if any): There is no error message, but the verbose output from PGSync looks like this:
If I rename the tables to "book" and "author", still keeping them in separate schemas, root node table changes are successfully synced and the verbose output from PGSync is the following:
The text was updated successfully, but these errors were encountered: