问题
I'm trying to create a DataSet for a Quicksight analysis. I'm using a custom query on a Postgresql Data Source.
Problem comes whenever I use Postgresql functions inside my query. The same query does, in fact, work on IntelliJ DataGrip and PgAdmin, for example, but I get a pretty unexpected error that states as follows:
QuickSight could not generate any output column after applying transformation. Check transform(s) and try again.
SELECT
users.name AS "User",
accounts.id AS "Account ID",
groups.name AS "Group",
account_balances.balance AS "Account Balance",
(
SELECT
account_balances.balance
FROM
account_balances
WHERE
account_balances.account_id = (
SELECT
accounts.id
FROM
accounts
WHERE
accounts.user_id = users.id
AND
accounts.account_type_id = 11
)
) AS "D Account Balance",
(
SELECT
decimal_value
FROM
user_custom_field_values
WHERE
user_custom_field_values.field_id = (
SELECT
user_custom_fields.id
FROM
user_custom_fields
WHERE
user_custom_fields.internal_name = 'capacity'
)
AND
owner_id = users.id
) AS "Capacity",
(
SELECT
decimal_value
FROM
user_custom_field_values
WHERE
user_custom_field_values.field_id = (
SELECT
user_custom_fields.id
FROM
user_custom_fields
WHERE
user_custom_fields.internal_name = 'Turnover'
)
AND
owner_id = users.id
) AS "Turnover",
(
SELECT value
FROM
user_custom_field_possible_values
WHERE
id in (
SELECT
possible_value_id
FROM
user_enum_values
WHERE
owner_id in (
SELECT
user_custom_field_values.id
FROM
user_custom_field_values
JOIN
user_custom_fields ON user_custom_fields.id=user_custom_field_values.field_id
WHERE
owner_id = users.id
AND
user_custom_fields.internal_name = 'contractType'
)
)
LIMIT 1
) AS "Contract Type",
(
SELECT
COUNT(id)
FROM
ads
WHERE
owner_id = users.id
AND
(ads.creation_date BETWEEN NOW() - interval '6 months' AND NOW())
) AS "ADs last 6 months",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.to_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
AND
(transfers.date BETWEEN NOW() - interval '3 months' AND NOW())
) AS "Sells last 3 months",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.to_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
AND
(transfers.date BETWEEN NOW() - interval '6 months' AND NOW())
) AS "Sells last 6 months",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.to_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
AND
(transfers.date BETWEEN NOW() - interval '12 months' AND NOW())
) AS "Sells last years",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.to_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
) AS "Sells",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.from_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
AND
(transfers.date BETWEEN NOW() - interval '3 months' AND NOW())
) AS "Purchases last 3 months",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.from_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
AND
(transfers.date BETWEEN NOW() - interval '6 months' AND NOW())
) AS "Purchases last 6 months",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.from_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
AND
(transfers.date BETWEEN NOW() - interval '12 months' AND NOW())
) AS "Purchases last year",
(
SELECT
SUM(transfers.amount)
FROM
transfers
WHERE
transfers.from_id = accounts.id
AND
transfers.chargeback_of_id IS NULL
AND
transfers.charged_back_by_id IS NULL
) AS "Purchases",
(
SELECT
account_limit_logs.credit_limit
FROM
account_limit_logs
WHERE
account_limit_logs.account_id = accounts.id
ORDER BY
account_limit_logs.id DESC
LIMIT 1
) AS "Account Limit"
FROM
users
JOIN
accounts ON accounts.user_id = users.id
JOIN
groups ON groups.id = users.user_group_id
JOIN
account_balances ON accounts.id = account_balances.account_id
WHERE
accounts.account_type_id = 4
Problem seems to be the - interval 'fooBar'
part.
Without that, the query goes smooth.
Anybody with a deep enough knowledge of AWS Quicksight and its secrets, care to help?
Even a different SQL solution to obtain the same result would be acceptable.
Thanks!
来源:https://stackoverflow.com/questions/58077766/quicksight-custom-query-postgresql-functions