We are trying to establish a DB link between Postgres and AWS Redshift DB (which isn't a problem) but we are using JOOQ to construct DB Query for the same.
What is working? We are able to write JOIN SQL queries for the data we want to fetch perfectly fine if the two tables were in the same database. For example, if we have a query:
SELECT somefields
FROM dblink('global_database'::text, '
SELECT
... some data selected...) t1(username text, location int, createdAt timestamptz)
JOIN user_meta t2 on "userId" = t1.userId
AND createdAt between ... some date range ...
WHERE ...'
GROUP BY ...
ORDER BY ... DESC;
Now we are constructing the query with JOOQ:
Query query = dslContext
.select(somefields))
.from(table(TABLE))
.rightJoin(TABLE_TWO).on(getJoinOnCondition())
.where(whereCondition)
.groupBy(groupByFields)
.orderBy(orderByFields)
.limit((int) pageRequest.getPageSize());
How to establish the DB link in the JOOQ Query?