I have this query:
INSERT INTO emailevents (shopid, userid, emailid, campaignid, variationid, type, createdon)
VALUES ($1,
(SELECT id FROM users WHERE mongoid=$2),
(SELECT id FROM emails WHERE mongoid=$3),
(SELECT id FROM campaigns WHERE mongoid=$4) AS cid,
(SELECT id FROM campaignvariations WHERE templateid=(SELECT id FROM templates WHERE mongoid=$5) AND campaignid=cid),
$6,
to_timestamp($7))
and I'm getting this error:Query failed: ERROR: syntax error at or near "AS"
I've tried putting cid inside the bracket, without success.
How should I use the alias?
Try to change to select instead of values as below
INSERT INTO emailevents (shopid, userid, emailid, campaignid, variationid, type, createdon)
select $1,
(SELECT id FROM users WHERE mongoid=$2),
(SELECT id FROM emails WHERE mongoid=$3),
(SELECT id FROM campaigns WHERE mongoid=$4) AS cid,
(SELECT id FROM campaignvariations WHERE templateid=(SELECT id FROM templates WHERE mongoid=$5) AND campaignid=(SELECT id FROM campaigns WHERE mongoid=$4)),
$6,
to_timestamp($7)
I think you should replace cit with (SELECT id FROM campaigns WHERE mongoid=$4) for variationid column
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With