|
18 | 18 | from sqlalchemy import select
|
19 | 19 | from sqlalchemy import String
|
20 | 20 | from sqlalchemy import Table
|
| 21 | +from sqlalchemy import ForeignKey |
21 | 22 | from sqlalchemy.schema import CreateTable
|
22 | 23 | from sqlalchemy.sql import column
|
23 | 24 | from sqlalchemy.sql import table
|
|
40 | 41 | trino_catalog='other'
|
41 | 42 | )
|
42 | 43 |
|
| 44 | +table_with_pk = Table( |
| 45 | + 'table_with_pk', |
| 46 | + metadata, |
| 47 | + Column('id', String, primary_key=True) |
| 48 | +) |
| 49 | + |
| 50 | +table_with_fk = Table( |
| 51 | + 'table_with_fk', |
| 52 | + metadata, |
| 53 | + Column('id', String, primary_key=True), |
| 54 | + Column('fk', String, ForeignKey('table_with_pk.id')) |
| 55 | +) |
| 56 | + |
| 57 | +table_with_unique = Table( |
| 58 | + 'table_with_constraint', |
| 59 | + metadata, |
| 60 | + Column('id', String, primary_key=True), |
| 61 | + Column('uniq', String, unique=True) |
| 62 | +) |
43 | 63 |
|
44 | 64 | @pytest.fixture
|
45 | 65 | def dialect():
|
@@ -170,3 +190,21 @@ def test_try_cast(dialect):
|
170 | 190 | statement = select(try_cast(table_without_catalog.c.id, String))
|
171 | 191 | query = statement.compile(dialect=dialect)
|
172 | 192 | assert str(query) == 'SELECT try_cast("table".id as VARCHAR) AS id \nFROM "table"'
|
| 193 | + |
| 194 | + |
| 195 | +def test_catalogs_create_table_with_pk(dialect): |
| 196 | + statement = CreateTable(table_with_pk) |
| 197 | + query = statement.compile(dialect=dialect) |
| 198 | + assert 'primary key' not in str(query).lower() |
| 199 | + |
| 200 | + |
| 201 | +def test_catalogs_create_table_with_fk(dialect): |
| 202 | + statement = CreateTable(table_with_fk) |
| 203 | + query = statement.compile(dialect=dialect) |
| 204 | + assert 'foreign key' not in str(query).lower() |
| 205 | + |
| 206 | + |
| 207 | +def test_catalogs_create_table_with_unique(dialect): |
| 208 | + statement = CreateTable(table_with_unique) |
| 209 | + query = statement.compile(dialect=dialect) |
| 210 | + assert 'unique' not in str(query).lower() |
0 commit comments