@@ -196,21 +196,27 @@ def make_sql_table(table, table_name, dialect=None, db_schema=None, constraints=
196
196
sql_column_kwargs = {}
197
197
198
198
if constraints :
199
- if isinstance (column .data_type , agate .Text ) and dialect == ' mysql' :
199
+ if isinstance (column .data_type , agate .Text ) and dialect in ( 'ingres' , ' mysql') :
200
200
length = table .aggregate (agate .MaxLength (column_name )) * decimal .Decimal (col_len_multiplier )
201
- if length > 21844 :
202
- # @see https://dev.mysql.com/doc/refman/5.7/en/string-type-overview.html
201
+ if (
202
+ # https://dev.mysql.com/doc/refman/8.2/en/string-type-syntax.html
203
+ dialect == 'mysql' and length > 21844 # 65,535 bytes divided by 3
204
+ # https://docs.actian.com/ingres/11.2/index.html#page/SQLRef/Character_Data_Types.htm
205
+ or dialect == 'ingres' and length > 10666 # 32,000 bytes divided by 3
206
+ ):
203
207
sql_column_type = TEXT
208
+ # If length is zero, SQLAlchemy may raise "VARCHAR requires a length on dialect mysql".
204
209
else :
205
- # If length is zero, SQLAlchemy may raise "VARCHAR requires a length on dialect mysql".
206
210
sql_type_kwargs ['length' ] = length if length >= min_col_len else min_col_len
207
211
208
212
# PostgreSQL and SQLite don't have scale default 0.
209
213
# @see https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
210
214
# @see https://www.sqlite.org/datatype3.html
211
- if isinstance (column .data_type , agate .Number ) and dialect in ('mssql' , 'mysql' , 'oracle' ):
215
+ if isinstance (column .data_type , agate .Number ) and dialect in ('ingres' , 'mssql' , 'mysql' , 'oracle' ):
216
+ # Ingres has precision range 1-39 and default 5, scale default 0.
217
+ # @see https://docs.actian.com/ingres/11.2/index.html#page/SQLRef/Storage_Formats_of_Data_Types.htm
212
218
# MySQL has precision range 1-65 and default 10, scale default 0.
213
- # @see https://dev.mysql.com/doc/refman/5.7 /en/fixed-point-types.html
219
+ # @see https://dev.mysql.com/doc/refman/8.2 /en/fixed-point-types.html
214
220
# Oracle has precision range 1-38 and default 38, scale default 0.
215
221
# @see https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832
216
222
# SQL Server has range 1-38 and default 18, scale default 0.
@@ -219,7 +225,7 @@ def make_sql_table(table, table_name, dialect=None, db_schema=None, constraints=
219
225
sql_type_kwargs ['scale' ] = table .aggregate (agate .MaxPrecision (column_name ))
220
226
221
227
# Avoid errors due to NO_ZERO_DATE.
222
- # @see https://dev.mysql.com/doc/refman/5.7 /en/sql-mode.html#sqlmode_no_zero_date
228
+ # @see https://dev.mysql.com/doc/refman/8.2 /en/sql-mode.html#sqlmode_no_zero_date
223
229
if not isinstance (column .data_type , agate .DateTime ):
224
230
sql_column_kwargs ['nullable' ] = table .aggregate (agate .HasNulls (column_name ))
225
231
@@ -276,14 +282,14 @@ def to_sql(self, connection_or_string, table_name, overwrite=False,
276
282
min_col_len = min_col_len , col_len_multiplier = col_len_multiplier )
277
283
278
284
if create :
279
- with connection .begin () as conn :
285
+ with connection .begin ():
280
286
if overwrite :
281
287
sql_table .drop (bind = connection , checkfirst = True )
282
288
283
289
sql_table .create (bind = connection , checkfirst = create_if_not_exists )
284
290
285
291
if insert :
286
- with connection .begin () as conn :
292
+ with connection .begin ():
287
293
insert = sql_table .insert ()
288
294
for prefix in prefixes :
289
295
insert = insert .prefix_with (prefix )
0 commit comments