Есть таблица artist и user_artist
artist:
- id (PK)
- name
user_artist:
- id (PK)
- userId(FK)
- artistId(FK)
- added
Следующий запрос возвращает ошибку
ссылки между базами не реализованы: user_artist.added
return db.query(`
SELECT artist.name AS "artistName", artist.id AS "artistId", user_artist.added
FROM user_artist
INNER JOIN artist
ON artist.id = user_artist."artistId"
WHERE user_artist."userId" = $(userId)
AND user_artist.added::timestamp < to_timestamp($(index) / 1000)
ORDER BY user_artist.added $(order)
LIMIT $(limit);`, obj);
Если убрать
ORDER BY user_artist.added $(order)
то ошибка исчезает.
Вот точная структура таблица user_artist
create table user_artist
(
"id" serial primary key,
"userId" serial REFERENCES user (id) on delete cascade,
"artistId" serial REFERENCES artist (id) on delete cascade,
"added" timestamp,
unique ("userId", "artistId")
);
Что не так?