Search code examples
pythonoracle11gponyorm

How do I use Oracle schema names in Pony ORM?


This is the query that I need:

SELECT * FROM SCHEMA.LOT

Using the following Python code

class Lot(db.Entity):
    _table_ = 'SCHEMA.LOT'
    lot_key = PrimaryKey(int)
    lot_id = Required(str)

this is the query that Pony ORM generates:

SELECT "l"."LOT_KEY", "l"."LOT_ID"
FROM "SCHEMA.LOT" "l"

Which naturally errors out with ORA-00942: table or view does not exist, because Oracle thinks that SCHEMA.LOT is the full table name. What I really need is for Pony ORM to generate a combination of the schema and the table name delimited by a dot that is not part of the string. So any of the following will work:

"SCHEMA"."LOT"
"SCHEMA".LOT
SCHEMA."LOT"

I've tried to trick Pony ORM by defining _table_ as 'SCHEMA"."LOT', but it just automatically converts this into the broken "SCHEMA"".""LOT". Infuriating!

Is there any way around this?


Solution

  • PonyORM does this because the dot is a valid name symbol.

    In order to specify compound name you need to define table name as a list of strings:

    class Lot(db.Entity):
        _table_ = ['SCHEMA', 'LOT']
        lot_key = PrimaryKey(int)
        lot_id = Required(str)