Giter Club home page Giter Club logo

Comments (19)

mtambos avatar mtambos commented on July 22, 2024 3

I think I got it working by setting

RedshiftDialect.supports_sequences = False
RedshiftDialect.preexecute_autoincrement_sequences = False
**RedshiftDialect.postfetch_lastrowid = True**

I'm still debugging things, but so far there's no been any primary key related errors.

from sqlalchemy-redshift.

mtambos avatar mtambos commented on July 22, 2024 1

Hey nwbvt, thank you so much!
It kind of works.
The '(psycopg2.ProgrammingError) relation "tablename_model_id_seq" does not exist' error is solved by setting those two variables to False, but now I'm getting the following:

sqlalchemy.orm.exc.FlushError: Instance [ENTITY] has a NULL identity key. 
If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. 
Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.

I guess there should be a

SELECT MAX([id_column])
FROM [entity_table]

immediately following the INSERT INTO [entity_table] statement.

I'm kind of new to SqlAlchemy, do you have any idea where/what should I modify in sqlalchemy_redshift to add this?

Thanks again,

Mario

from sqlalchemy-redshift.

mtambos avatar mtambos commented on July 22, 2024 1

@aboedo done

from sqlalchemy-redshift.

rogaha avatar rogaha commented on July 22, 2024 1

Any updates on this?

from sqlalchemy-redshift.

jklukas avatar jklukas commented on July 22, 2024

I haven't run into that. I'd be interested to see what situations produce this error.

from sqlalchemy-redshift.

mtambos avatar mtambos commented on July 22, 2024

Hi guys,

I'm currently trying to deal with this problem.
Anyone knows some solution/workaround for it?

Thanks!

from sqlalchemy-redshift.

nwbvt avatar nwbvt commented on July 22, 2024

Its a pretty simple fix which I was able to make on my fork, unfortunately I didn't get a chance to resolve the questions that came up from the pull request (I blame a combination of a conference, illness, and me just plain forgetting about it).

from sqlalchemy-redshift.

nwbvt avatar nwbvt commented on July 22, 2024

I think that was against an older version though, so it might not work if you are using something more recent.

from sqlalchemy-redshift.

aboedo avatar aboedo commented on July 22, 2024

@mtambos your solution works. could you make a PR?

from sqlalchemy-redshift.

graingert avatar graingert commented on July 22, 2024

I'm pretty sure it's impossible

from sqlalchemy-redshift.

rogaha avatar rogaha commented on July 22, 2024

setting the autoincrement=False in the class definition solved the issue for me.

from sqlalchemy-redshift.

rogaha avatar rogaha commented on July 22, 2024

it prevents the sequence auto increment behavior in sqlalchemy when you try to insert something without the id (in my case an identity field).

from sqlalchemy-redshift.

graingert avatar graingert commented on July 22, 2024

I believe the architecture of redshift means that you must use application generated IDs

from sqlalchemy-redshift.

rogaha avatar rogaha commented on July 22, 2024

not for identity fields:

IDENTITY(seed, step)
Clause that specifies that the column is an IDENTITY column. An IDENTITY column contains unique auto-generated values. These values start with the value specified as seed and increment by the number specified as step. The data type for an IDENTITY column must be either INT or BIGINT.

ref. http://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html

from sqlalchemy-redshift.

graingert avatar graingert commented on July 22, 2024

Yeah but there's no way of getting the ID back

from sqlalchemy-redshift.

MarSoft avatar MarSoft commented on July 22, 2024

@graingert, according to this answer (and one of the comments above) you can execute INSERT and then SELECT MAX(id) in the same transaction and it is supposed to work.

from sqlalchemy-redshift.

graingert avatar graingert commented on July 22, 2024

from sqlalchemy-redshift.

waltercool avatar waltercool commented on July 22, 2024

Sorry to re-open this topic, but facing same problem here.

I know the proposed solution was accepted but later reverted as may seen here: b11bf01

Which solution would be acceptable so? Getting a crash like it works currently, or some workaround which makes it works at some cases?

I personally prefer the "sometimes works", but with some "warning" instead, so may be properly managed by the developer instead. Crashing with error f405 poor like managed. Personal opinion.

from sqlalchemy-redshift.

graingert avatar graingert commented on July 22, 2024

Fixing this with a better error is probably a good idea.

Eg crashing with an error and a link to a discussion on how to use application generated PKs with SQLAlchemy ORM and redshift

from sqlalchemy-redshift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.