Skip to content

Commit aa46b7a

Browse files
committed
Adding redshift create table special syntax.
Adding documentation
1 parent b33bd31 commit aa46b7a

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

redshift_sqlalchemy/dialect.py

+43-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@
88

99

1010
class RedShiftDDLCompiler(PGDDLCompiler):
11+
''' Handles Redshift specific create table syntax.
12+
13+
Users can specify the DISTSTYLE, DISTKEY, SORTKEY and ENCODE properties per
14+
table and per column.
15+
16+
Table level properties can be set using the dialect specific syntax. For
17+
example, to specify a distkey and style you apply the following ::
18+
19+
table = Table(metadata,
20+
Column('id', Integer, primary_key=True),
21+
Column('name', String),
22+
redshift_diststyle="KEY",
23+
redshift_distkey="id"
24+
redshift_sortkey=["id", "name"]
25+
)
26+
27+
A single sortkey can be applied without a wrapping list ::
28+
29+
table = Table(metadata,
30+
Column('id', Integer, primary_key=True),
31+
Column('name', String),
32+
redshift_sortkey="id"
33+
)
34+
35+
Column level special syntax can also be applied using the column info
36+
dictionary. For example, we can specify the encode for a column ::
37+
38+
table = Table(metadata,
39+
Column('id', Integer, primary_key=True),
40+
Column('name', String, info={"encode":"lzo"})
41+
)
42+
43+
We can also specify the distkey and sortkey options ::
44+
45+
table = Table(metadata,
46+
Column('id', Integer, primary_key=True),
47+
Column('name', String,
48+
info={"distkey":True, "sortkey":True})
49+
)
50+
51+
'''
1152

1253
def post_create_table(self, table):
1354
text = ""
@@ -34,9 +75,8 @@ def post_create_table(self, table):
3475
return text
3576

3677
def get_column_specification(self, column, **kwargs):
37-
''' Redshift doesn't support serial types, so they have been removed
38-
here.
39-
'''
78+
# aron - Apr 21, 2014: Redshift doesn't support serial types. So I
79+
# removed support for them here.
4080
colspec = self.preparer.format_column(column)
4181
colspec += " " + self.dialect.type_compiler.process(column.type)
4282

0 commit comments

Comments
 (0)