错误:日期类型“ InvoiceDate”的输入语法无效

时间:2019-05-20 07:00:23

标签: postgresql postgresql-9.4

我正在运行3个PostgreSQL查询,但运行正常,但是当我对所有3个查询执行UNION ALL时,我得到了错误。

下面是我的查询。

 SELECT 'ContactName' as "ContactName",'InvoiceNumber' as "InvoiceNumber",'InvoiceDate' as "InvoiceDate",'DueDate' as "DueDate",'Description' as "Description",'Quantity' as "Quantity",'UnitAmount' as "UnitAmount",'AccountCode' as "AccountCode",'TaxType' as "TaxType",'TaxAmount' as "TaxAmount";

结果:成功

 SELECT c.organization_name as "CUSTOMER",CONCAT(i.id) as "INVOICE",DATE(i.create_datetime) as "INVOICE_DATE",DATE(i.due_date) as "DUE_DATE",CONCAT('Invoice ID1-',i.id,' - REGULAR VAT LINES') as "DESCRIPTION",'1' AS "QTY",round((COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0')*5),2) as SUB_TOTAL_DUE_AT_STANDARD_VAT20,'200' AS "ACCOUNT_CODE",'20% (VAT on Income)' AS "TAX_TYPE",round((COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0')*5),2) as VAT_AT_STANDARD_VAT20 FROM invoice i,base_user bu,contact c WHERE bu.id = i.user_id AND c.user_id = i.user_id AND i.total != 0 AND i.is_review = 0 AND i.deleted = 0 AND c.organization_name NOT LIKE 'Skyrack%' AND c.organization_name NOT LIKE 'Simetric%' AND c.organization_name NOT LIKE 'PBX Test%' AND c.organization_name NOT LIKE 'ZZZTEST%';

结果:成功

 SELECT c.organization_name as "CUSTOMER",CONCAT(i.id) as "INVOICE",DATE(i.create_datetime) as "INVOICE_DATE",DATE(i.due_date) as "DUE_DATE",CONCAT('Invoice ID1-',i.id,' - REVCHG VAT LINES') as "DESCRIPTION",'1' AS "QTY",round(((i.total - COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0'))-(COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0')* 5)),2) AS "SUB_TOTAL_DUE_AT_VAT0",'210' AS "ACCOUNT_CODE",'Domestic Reverse Charge' AS "TAX_TYPE",'0' AS "VAT_AT_STANDARD_VAT0" FROM invoice i,base_user bu,contact c WHERE bu.id = i.user_id AND c.user_id = i.user_id AND i.total != 0 AND i.is_review = 0 AND i.deleted = 0 AND c.organization_name NOT LIKE 'Skyrack%' AND c.organization_name NOT LIKE 'Simetric%' AND c.organization_name NOT LIKE 'PBX Test%' AND c.organization_name NOT LIKE 'ZZZTEST%';

结果:成功

现在当我执行UNION ALL时,对于所有3个查询,

 SELECT 'ContactName' as "ContactName",'InvoiceNumber' as "InvoiceNumber",'InvoiceDate' as "InvoiceDate",'DueDate' as "DueDate",'Description' as "Description",'Quantity' as "Quantity",'UnitAmount' as "UnitAmount",'AccountCode' as "AccountCode",'TaxType' as "TaxType",'TaxAmount' as "TaxAmount" UNION ALL SELECT c.organization_name as "CUSTOMER",CONCAT(i.id) as "INVOICE",DATE(i.create_datetime) as "INVOICE_DATE",DATE(i.due_date) as "DUE_DATE",CONCAT('Invoice ID1-',i.id,' - REGULAR VAT LINES') as "DESCRIPTION",'1' AS "QTY",round((COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0')*5),2) as SUB_TOTAL_DUE_AT_STANDARD_VAT20,'200' AS "ACCOUNT_CODE",'20% (VAT on Income)' AS "TAX_TYPE",round((COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0')*5),2) as VAT_AT_STANDARD_VAT20 FROM invoice i,base_user bu,contact c WHERE bu.id = i.user_id AND c.user_id = i.user_id AND i.total != 0 AND i.is_review = 0 AND i.deleted = 0 AND c.organization_name NOT LIKE 'Skyrack%' AND c.organization_name NOT LIKE 'Simetric%' AND c.organization_name NOT LIKE 'PBX Test%' AND c.organization_name NOT LIKE 'ZZZTEST%' UNION ALL SELECT c.organization_name as "CUSTOMER",CONCAT(i.id) as "INVOICE",DATE(i.create_datetime) as "INVOICE_DATE",DATE(i.due_date) as "DUE_DATE",CONCAT('Invoice ID1-',i.id,' - REVCHG VAT LINES') as "DESCRIPTION",'1' AS "QTY",round(((i.total - COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0'))-(COALESCE(NULLIF((SELECT sum(il.amount) AS vat FROM invoice_line il WHERE il.invoice_id = i.id AND il.description LIKE '%VAT%' AND il.description != 'VAT @20%' AND il.item_id = 200 AND il.deleted = 0),null),'0')* 5)),2) AS "SUB_TOTAL_DUE_AT_VAT0",'210' AS "ACCOUNT_CODE",'Domestic Reverse Charge' AS "TAX_TYPE",'0' AS "VAT_AT_STANDARD_VAT0" FROM invoice i,base_user bu,contact c WHERE bu.id = i.user_id AND c.user_id = i.user_id AND i.total != 0 AND i.is_review = 0 AND i.deleted = 0 AND c.organization_name NOT LIKE 'Skyrack%' AND c.organization_name NOT LIKE 'Simetric%' AND c.organization_name NOT LIKE 'PBX Test%' AND c.organization_name NOT LIKE 'ZZZTEST%';

结果:失败

  

错误:错误:日期类型“ InvoiceDate”的输入语法无效

我没有得到造成此错误的原因及解决方法?enter image description here

0 个答案:

没有答案