Lina Lina - 4 months ago 8
SQL Question

Syntax error in Postgres query

I written select query in PostgreSQL DB but it is giving me syntax error.

select order.c_doctype_id , doc.DocSubTypeSO
from c_order order
inner join c_doctype doc on(order.c_doctype_id = doc.c_doctype_id)
where order.c_order_id =1000674


In above query it giving me syntax error near order.

Answer

Use double quotes "" for reserved words :

select "order".c_doctype_id , doc.DocSubTypeSO 
from c_order "order"
inner join c_doctype doc on("order".c_doctype_id = doc.c_doctype_id)
where "order".c_order_id =1000674

Or just don't use reserved words:

select o.c_doctype_id , doc.DocSubTypeSO 
from c_order o
inner join c_doctype doc on(o.c_doctype_id = doc.c_doctype_id)
where o.c_order_id =1000674
Comments