Olukayode Oluwole
asked on
How do I create a view in PostgreSQL
I have a view in SQLserver which works perfectly and now
need to have the same view in PostgreSQL
The view in SQLServer has UNIONS and involves about 5 tables (Attached in the notepad file)
I test my Postgre installation with a simple view and it worked but on trying my actual
view with the script from SQLServer I got and error
I treied to narrow it down to just a simple select from 1 table and it did not work
below is the error and my table and the fields i was trying to create a view from
What could i be doing wrong
Thanks
Olukay
completeview.txt
need to have the same view in PostgreSQL
The view in SQLServer has UNIONS and involves about 5 tables (Attached in the notepad file)
I test my Postgre installation with a simple view and it worked but on trying my actual
view with the script from SQLServer I got and error
I treied to narrow it down to just a simple select from 1 table and it did not work
below is the error and my table and the fields i was trying to create a view from
What could i be doing wrong
Thanks
Olukay
completeview.txt
ASKER
I have changed the table names to lower case and the view gets created
But if i have 2 views the results of which need to be concatenated
how does PostgreSQL handle this
In SqlServer UNION ALL as below does it
Whats the equivalent of UNION ALL in PostgreSQL
Thanks
SELECT arsales.ARSALEDate AS Date01, arsales.ARSALEDocumentType AS Type, - (1 * arsalesdetail.ARSALEDQty) AS Qty1,
arsalesdetail.ARSALEDItemC ost AS Cost01, arsales.ARSALEExtDocumentN o AS DocNo, arsales.ARSALECheckNumber AS Memo,
arsalesdetail.ARSALEDItemI d AS ID, loctab.loc_desc AS location, arsales.ARSALEBillTo AS Customer
FROM arsales,arsalesdetail,loct ab
WHERE arsales.ARSALEPostedYN = '1'
AND arsales.ARSALEDocumentType = 'Invoice'
AND arsales.ARSALEDocumentNo = arsalesdetail.ARSALEDDocum entNo
AND arsales.in_user = loctab.location
UNION ALL
SELECT arsales.ARSALEDate AS Date01, arsales.ARSALEDocumentType AS Type, arsalesdetail.ARSALEDQty AS Qty1,
arsalesdetail.ARSALEDItemC ost AS Cost01, arsales.ARSALEExtDocumentN o AS DocNo, arsales.ARSALECheckNumber AS Memo,
arsalesdetail.ARSALEDItemI d AS ID, loctab.loc_desc AS location, arsales.ARSALEBillTo AS Customer
FROM arsales,arsalesdetail,loct ab
WHERE arsales.ARSALEPostedYN = '1'
AND arsales.ARSALEDocumentType = 'Return'
AND arsales.in_user = loctab.location
AND arsales.ARSALEDocumentNo = arsalesdetail.ARSALEDDocum entNo
But if i have 2 views the results of which need to be concatenated
how does PostgreSQL handle this
In SqlServer UNION ALL as below does it
Whats the equivalent of UNION ALL in PostgreSQL
Thanks
SELECT arsales.ARSALEDate AS Date01, arsales.ARSALEDocumentType
arsalesdetail.ARSALEDItemC
arsalesdetail.ARSALEDItemI
FROM arsales,arsalesdetail,loct
WHERE arsales.ARSALEPostedYN = '1'
AND arsales.ARSALEDocumentType
AND arsales.ARSALEDocumentNo = arsalesdetail.ARSALEDDocum
AND arsales.in_user = loctab.location
UNION ALL
SELECT arsales.ARSALEDate AS Date01, arsales.ARSALEDocumentType
arsalesdetail.ARSALEDItemC
arsalesdetail.ARSALEDItemI
FROM arsales,arsalesdetail,loct
WHERE arsales.ARSALEPostedYN = '1'
AND arsales.ARSALEDocumentType
AND arsales.in_user = loctab.location
AND arsales.ARSALEDocumentNo = arsalesdetail.ARSALEDDocum
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am ok now good.
ASKER
Great support. Thanks
More info here
So, modify the syntax to this:
Open in new window