我有我的sql編輯器運行完美的sql語句,但是當我把它放在我的javascript函數中時,它告訴我無效的列爲我的客戶端ID。爲什麼我的sql語句在我的編輯器中工作,但不是我的JS功能?
function getFeedposts(data) {
var limit = data.dollarLimit;
var client_id = data.salesforce_username;
var sqlQuery = `select coalesce(advertiser,'') as advertiser,
coalesce(partner,'') as partner,
coalesce(advertiser,'') || ' via ' || coalesce(partner,'') as line1,
' - SSP: blah' as line2,
' - Lead Date: ' || date as line3,
'Yesterday''s Activity' as line4,
' - Impressions: ' || coalesce(impressions,0) as line5,
' - CPM: $' || coalesce(round(ecpm,2),0) as line6,
' - Spend: $' || coalesce(round(revenue,2),0) as line7,
'Yesterday''s Spend Breakout' as line7a,
coalesce(device_type,'') as line8,
'Running Spend Totals' as line9,
' - 3 Day Spend: $' || coalesce(round(three,2),0) as line10,
' - 7 Day Spend: $' || coalesce(round(seven,2),0) as line11,
' - 30 Day Spend: $' || coalesce(round(thirty,2),0) as line12,
coalesce(round(thirty,2),0) as line13,
coalesce(round(seven,2),0) as line14,
coalesce(round(three,2),0) as line15,
coalesce(round(three,2),0) as line15,
client_id as client_id
from
(select advertiser, partner, date, impressions, ecpm, revenue, device_type, client_id
,(select sum(m.revenue)
FROM blahblah as m
WHERE m.date > rl.date -30
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as thirty
,(select sum(m.revenue)
FROM blahblah as m
WHERE m.date > rl.date -7
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as seven
,(select sum(revenue)
FROM blahblah as m
WHERE m.date > rl.date -3
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as three
from blahblah as rl
) as idunno
WHERE
date = to_date('${data.date}','mm-dd-yyyy')
and revenue > 1 and client_id ='[email protected]'
`;
queryRDS(sqlQuery, data);
}
這個工作,但是當我做
function getFeedposts(data) {
var limit = data.dollarLimit;
var client_id = data.salesforce_username;
var sqlQuery = `select coalesce(advertiser,'') as advertiser,
coalesce(partner,'') as partner,
coalesce(advertiser,'') || ' via ' || coalesce(partner,'') as line1,
' - SSP: blah' as line2,
' - Lead Date: ' || date as line3,
'Yesterday''s Activity' as line4,
' - Impressions: ' || coalesce(impressions,0) as line5,
' - CPM: $' || coalesce(round(ecpm,2),0) as line6,
' - Spend: $' || coalesce(round(revenue,2),0) as line7,
'Yesterday''s Spend Breakout' as line7a,
coalesce(device_type,'') as line8,
'Running Spend Totals' as line9,
' - 3 Day Spend: $' || coalesce(round(three,2),0) as line10,
' - 7 Day Spend: $' || coalesce(round(seven,2),0) as line11,
' - 30 Day Spend: $' || coalesce(round(thirty,2),0) as line12,
coalesce(round(thirty,2),0) as line13,
coalesce(round(seven,2),0) as line14,
coalesce(round(three,2),0) as line15,
coalesce(round(three,2),0) as line15,
client_id as client_id
from
(select advertiser, partner, date, impressions, ecpm, revenue, device_type, client_id
,(select sum(m.revenue)
FROM blahblah as m
WHERE m.date > rl.date -30
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as thirty
,(select sum(m.revenue)
FROM blahblah as m
WHERE m.date > rl.date -7
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as seven
,(select sum(revenue)
FROM blahblah as m
WHERE m.date > rl.date -3
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as three
from blahblah as rl
) as idunno
WHERE
date = to_date('${data.date}','mm-dd-yyyy')
and revenue >
`;
sqlQuery += limit + 'and client_id =' + client_id;
queryRDS(sqlQuery, data);
}
我想知道爲什麼它會告訴無效列是做這樣當電流CLIENT_ID但電子郵件地址時,我硬編碼它完美罰款任何幫助,將不勝感激
這是錯誤消息我收到
RDS query successful
finished writing to rds
{ [error: column "joseph" does not exist]
name: 'error',
length: 101,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '1596',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '3090',
routine: 'errorMissingColumn' }
我會說這是因爲你沒有在字符串中的空間在該位的代碼'極限+「和CLIENT_ID =''所以它的輸出結果類似於'and revenue> 2 and client_id' – George
如果你記錄'client_id',你會得到什麼? – Pineda
@Pineda我得到的電子郵件地址我期望 –