On 04/26/2016 11:19 AM, Piotr Dobrogost wrote:
Questions I asked in my last post are concerned more with implementing
IDENTITY for Oracle. Here the situation is not so simple and simply
replacing text is not possible as "GENERATE AS IDENTITY" phrase must
be placed in right order with regard to other keywords. That's what
made me looking at DDLCompiler.get_column_specification() and what
lead me to asking the questions I asked. I assure you I've read the
link you sent before asking my questions. This example just doesn't
seem to answer those questions.
I'd like you to know that I'm treating our conversation as occasion to
learn more about SA and to know how things should be done. Replacing
NOT NULL with NULL or vice versa is just very specific way of solving
particular problem and does not bring me closer to knowing how to
manipulate DDL for column creation in general.
OK so for the "GENERATE AS IDENTITY", first off we'd like to support
that for Oracle, and that would involve lots of version detection /
switches / new logic added to oracle/base.py, as it changes not only the
DDL but a lot of the specific workings of the dialect in how it renders
an INSERT statement.
As far as getting just the DDL right now, the "text.replace()" approach
is still close to the most expedient approach, which is to get at that
text, then use a regular expression replace in order to add "GENERATE AS
IDENTITY". I'd do it like this:
from sqlalchemy.schema import CreateColumn
@compiles(CreateColumn, "oracle")
def _do_thing(element, compiler, **kw):
text = compiler.visit_create_column(element, **kw)
if element.element.info.get('use_identity', False):
text = re.sub(r'(NUMBER|INTEGER) ', r'\1 GENERATED ALWAYS AS
IDENTITY', text)
return text
then in Column I'd set up a flag as follows:
Column('mycol', Numeric, info={"use_identity": True})
For your approach with NULL, I'd still advise using @compiles for that
as well. Looking at the engine.name and changing the column.nullable is
fine but it means you need to coordinate the engine with the table
metadata itself which is awkward and wouldn't work if your application
had multiple engines in one process.
Regards,
Piotr Dobrogost
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.