En postgresql no podemos unir dos select si uno de los dos campos no coincide en formato.

La select intenta unir los gastos de una tabla

 

 
 
(select ‘GA’, cast (t0.id as varchar), t0.create_date,’0′,0, (select sum(debit) from account_model_line where create_uid = t1.model_id)as total,’ ‘ from account_subscription_line t0
left join account_subscription t1 on t0.create_uid = t1.create_uid)

select ‘GA’,number,date_invoice,partner_id,0,amount_total,state from account_invoice where type = ‘in_invoice’

union(select ‘GA’, 0.id , t0.create_date,’0′,0, (select sum(debit) from account_model_line where create_uid = t1.model_id)as total,’ ‘

from account_subscription_line t0left join account_subscription t1 on t0.create_uid = t1.create_uid)

 

 

Nos daria un mensaje como este

 

UNION types character varying and integer cannot be matched

 

Solucion

Usamos cast para convertir nuestro campo en el que nos conviene en mi casa varchar seria cast(campo as tipo)

 

 

select ‘GA’,number,date_invoice,partner_id,0,amount_total,state from account_invoice where type = ‘in_invoice’

union

(select ‘GA’, cast (t0.id as varchar), t0.create_date,’0′,0, (select sum(debit) from account_model_line where create_uid = t1.model_id)as total,’ ‘ from account_subscription_line t0

left join account_subscription t1 on t0.create_uid = t1.create_uid)

 

Por admin

Deja una respuesta

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO