This topic is locked

Update a table with aliases in the query

7/15/2014 4:44:22 PM
PHPRunner General questions
D
drgregory author

Dear Sirs,
I've wrote you before, telling that I have a PostgreSQL database and more than 20 projects over it, many of which have queries like this simplified example:
SELECT

esp.strespiden,

esp.strespdeno,

esp.strorgtipo,

esp.strorgiden,

org.strorgdeno,

esp.strusucodi

FROM schema.tblaaaaaaa AS esp

LEFT JOIN schema.tblbbbbbbb AS org

ON esp.strorgtipo = org.strorgtipo AND

esp.strorgiden = org.strorgiden

ORDER BY esp.strespiden
As you can see, the main table tblaaaaaaa has a foreign key on tblbbbbbbb (the fields are strorgtipo and strorgiden) just to only pick up a description from tblbbbbbbb and display it in the List page.
This query also has Add and Edit pages. In both of them, displayed and editable fields are ONLY those referenced with the esp alias (strespiden, strespdeno, strorgtipo, strorgiden, strusucodi). The strespiden field is the primary key on tblaaaaaaa, so it only appears in the Add page.
Well, when I try to insert a record, PHPRunner fails and shows an error message (actually from the PostgreSQL engine), like this (I format it and show you the relevant parts):
ERROR: column "esp" of relation "tblaaaaaaa" does not exist at character 41

STATEMENT:

insert into "schema"."tblaaaaaaa" (esp.strespiden, esp.strespdeno, esp.strorgtipo, esp.strorgiden, esp.strusucodi) values ...

This is because in PostgreSQL aliases are not allowed in INSERT, UPDATE or DELETE. This is an annoying situation, it appears in PHPRunner 5.2 and at least 6.0, and I don't understand why PHPRunner doesn't delete the alias prefix when building the final query.
How can I fix this true basic problem? Please consider that I would like to have only one method of updating the database, and to avoid use of alternative solutions (Add(), Update(), Delete() functions from dal class and so on).
Thank you in advance.

DrGregory