[SQL] FirebirdSQL to PostgreSQL
[SQL] FirebirdSQL to PostgreSQL
От:
Ertan Küçükoğlu <ertan.kucukoglu@1nar.com.tr>
Дата:
Hello, I have below sql running fine on FirebirdSQL but not on PostgreSQL. As I am not the editor of the SQL, I cannot fix it to work with PostgreSQL. Any help is appreciated. Not posting table details not to bloat the message. I do not have Access to database right now. Error Message I receive is something like: Field "kaynak" not found on right table SELECT RAPOR_EK.KAYNAK, RAPOR_EK.SEBEP, COALESCE(DT.IAIK_OG, 0) AS "IAIK_OG", COALESCE(DT.IAIK_AG, 0) AS "IAIK_AG", COALESCE(DT.IAIK_TOPLAM, 0) AS "IAIK_TOPLAM", COALESCE(DT.IADK_OG, 0) AS "IADK_OG", COALESCE(DT.IADK_AG, 0) AS "IADK_AG", COALESCE(DT.IADK_TOPLAM, 0) AS "IADK_TOPLAM", COALESCE(DT.GNLTOPLAM, 0) AS "GNLTOPLAM" FROM RAPOR_EK LEFT JOIN ( SELECT M.TKS_KAYNAGAGORE AS "KAYNAK", M.TKS_SEBEBEGORE AS "SEBEP", (sum(M.TES_IMARALANICIOG)/(select sum(I.ILC_IMARALANICI_OG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ')*60) as "IAIK_OG", (sum(M.TES_IMARALANICIAG)/(select sum(I.ILC_IMARALANICI_AG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ')*60) as "IAIK_AG", ((sum(M.TES_IMARALANICIOG) + sum(M.TES_IMARALANICIAG)) / ((select sum(I.ILC_IMARALANICI_OG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ') + (select sum(I.ILC_IMARALANICI_AG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ'))*60) AS "IAIK_TOPLAM", (sum(M.TES_IMARALANDISIOG)/(select sum(I.ILC_IMARALANDISI_OG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ')*60) as "IADK_OG", (sum(M.TES_IMARALANDISIAG)/(select sum(I.ILC_IMARALANDISI_AG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ')*60) as "IADK_AG", ((sum(M.TES_IMARALANDISIOG) + sum(M.TES_IMARALANDISIAG)) / ((select sum(I.ILC_IMARALANDISI_OG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ') + (select sum(I.ILC_IMARALANDISI_AG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ'))*60) AS "IADK_TOPLAM", ((sum(M.TES_IMARALANICIOG) + sum(M.TES_IMARALANICIAG) + (sum(M.TES_IMARALANDISIOG) + sum(M.TES_IMARALANDISIAG))) / ((select sum(I.ILC_IMARALANICI_OG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ') + (select sum(I.ILC_IMARALANICI_AG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ') + (select sum(I.ILC_IMARALANDISI_OG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ') + (select sum(I.ILC_IMARALANDISI_AG) from ILCELER_TABLOSU I where I.ILCEADI = 'CİHANBEYLİ'))*60) AS "GNLTOPLAM" FROM TABLO_MEDAS M WHERE M.T_ILCE = 'CİHANBEYLİ' AND M.T_BILDIRIMEGORE = 'Bildirimsiz' AND M.TKS_SUREYEGORE = 'Uzun' AND (M.T_BASLAMATARIHI >= '2015-01-01' AND T_BASLAMATARIHI <= '2015-01-31 23:59:59') GROUP BY M.TKS_KAYNAGAGORE, M.TKS_SEBEBEGORE ) DT USING (KAYNAK, SEBEP) ORDER BY KAYNAK, SEBEP -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
Re: [SQL] FirebirdSQL to PostgreSQL
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Ertan Küçükoğlu writes: > I have below sql running fine on FirebirdSQL but not on PostgreSQL. As I am > not the editor of the SQL, I cannot fix it to work with PostgreSQL. Any help > is appreciated. You're not being consistent about quoting, e.g. you've got this > COALESCE(DT.IAIK_OG, 0) AS "IAIK_OG", which seems to be trying to reference this field of the DT subselect: > (sum(M.TES_IMARALANICIOG)/(select sum(I.ILC_IMARALANICI_OG) from > ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IAIK_OG", but it won't match because IAIK_OG is not the same name as "IAIK_OG". (According to Postgres --- some other systems treat this differently.) Best rule is to always quote a particular name or never quote it. regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
Re: [SQL] FirebirdSQL to PostgreSQL
От:
Ertan Küçükoğlu <ertan.kucukoglu@1nar.com.tr>
Дата:
> -----Original Message----- > From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Tom Lane > Sent: Tuesday, September 12, 2017 3:11 PM > To: Ertan Küçükoğlu > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] FirebirdSQL to PostgreSQL > > Ertan Küçükoğlu writes: >> I have below sql running fine on FirebirdSQL but not on PostgreSQL. As >> I am not the editor of the SQL, I cannot fix it to work with >> PostgreSQL. Any help is appreciated. > > You're not being consistent about quoting, e.g. you've got this > >> COALESCE(DT.IAIK_OG, 0) AS "IAIK_OG", > > which seems to be trying to reference this field of the DT subselect: > >> (sum(M.TES_IMARALANICIOG)/(select sum(I.ILC_IMARALANICI_OG) from >> ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IAIK_OG", > > but it won't match because IAIK_OG is not the same name as "IAIK_OG". > (According to Postgres --- some other systems treat this differently.) Best rule is to always quote a particular name or never quote it. > > regards, tom lane Thanks you Tom. That was it. For now, I simply removed all quotes and query executed just fine. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql