में Redshift पहचान कॉलम हैंडलिंग मैं SqLAlchemy को Redshift से कनेक्ट करने के लिए redshift-sqlalchemy पैकेज का उपयोग कर रहा हूं।SQLAlchemy
create table if not exists companies (
id bigint identity primary key,
name varchar(1024) not null
);
SQLAlchemy पक्ष मैं यह इतना की तरह मैप किया गया है पर:: Redshift में मैं एक साधारण "कंपनियों" तालिका है
Base = declarative_base()
class Company(Base):
__tablename__ = 'companies'
id = Column(BigInteger, primary_key=True)
name = Column(String)
अगर मैं एक कंपनी बनाने का प्रयास करें:
company = Company(name = 'Acme')
session.add(company)
session.commit()
तो मुझे यह त्रुटि मिलती है:
sqlalchemy.exc.StatementError: (raised as a result of Query-invoked autoflush;
consider using a session.no_autoflush block if this flush is occurring prematurely)
(sqlalchemy.exc.ProgrammingError) (psycopg2.ProgrammingError)
relation "companies_id_seq" does not exist
[SQL: 'select nextval(\'"companies_id_seq"\')']
[SQL: u'INSERT INTO companies (id, name)
VALUES (%(id)s, %(name)s)'] [parameters: [{'name': 'Acme'}]]
समस्या यह निश्चित रूप से है कि एसक्यूएलकेमी एक ऑटो-वृद्धिशील अनुक्रम की उम्मीद कर रहा है - पोस्टग्रेज़ और अन्य पारंपरिक डीबी के साथ मानक तकनीक। लेकिन Redshift में अनुक्रम नहीं हैं, इसके बजाय यह स्वत: जेनरेट किए गए अद्वितीय मानों (आवश्यक अनुक्रमिक नहीं) के लिए "पहचान कॉलम" प्रदान करता है। इस काम को कैसे बनाया जाए इस पर कोई सलाह? स्पष्ट होने के लिए, मुझे ऑटो-वृद्धि के बारे में परवाह नहीं है, केवल अद्वितीय प्राथमिक कुंजी मानों की आवश्यकता है।
संबंधित चर्चा यहाँ: https://github.com/binarydud/redshift_sqlalchemy/issues/24 एक फिक्स दावा है, लेकिन है कि यह करने के लिए एक ठीक है मुझे ऐसा लगता है एक संबंधित लेकिन अलग-अलग बग, अर्थात् ओआरएम के माध्यम से एक नई प्रविष्टि डालने के बजाय टेबल निर्माण, जो मामला है, मैं –