meilisync icon indicating copy to clipboard operation
meilisync copied to clipboard

Join multiple sql tables

Open laigor opened this issue 1 year ago • 3 comments

Please tell me how to get source parameters inside the plugin? I want to supplement with data from other tables by making SQL queries inside pre_event.

laigor avatar Oct 24 '24 15:10 laigor

Try writing a view? eg for postgresql

CREATE VIEW meilisearch_view AS
SELECT
    users.id_key,
    other.foo,
FROM
    users
LEFT JOIN
    other ON users.id_key = other.user_id;

nMessage avatar Oct 30 '24 13:10 nMessage

If I use views in mysql, database changes are not tracked.

laigor avatar Nov 04 '24 11:11 laigor

A view will not be output by wal2json (in the case of postgresql) and probaly neither will mysql.

Using a materialized view works fine since the data is physically stored in a table. Just keep in mind you have to refresh the materialized view after updating any of the source tables

CREATE MATERIALIZED VIEW meilisearch_view AS
SELECT
    users.id_key,
    other.foo,
FROM
    users
LEFT JOIN
    other ON users.id_key = other.user_id;

tcommandeur avatar Dec 30 '24 14:12 tcommandeur