Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

visit_create_table method added to dialect#3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
PeterDKay merged 1 commit intomainfromtask/if-not-exists-to-create-table
Jul 19, 2023
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletionssrc/databricks/sqlalchemy/dialect/base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import re
from sqlalchemy import util, exc
from sqlalchemy.sql import compiler, sqltypes, ColumnElement


Expand DownExpand Up@@ -64,3 +65,56 @@ def _format_table_from_column(self, column_object, use_schema=False):
name = schema_table_column.split(".")[0] + '.' + name

return name

def visit_create_table(self, create, **kw):
table = create.element
preparer = self.preparer

text = "\nCREATE "
if table._prefixes:
text += " ".join(table._prefixes) + " "

# Default to 'IF NOT EXISTS'
text += "TABLE IF NOT EXISTS "

text += preparer.format_table(table) + " "

create_table_suffix = self.create_table_suffix(table)
if create_table_suffix:
text += create_table_suffix + " "

text += "("

separator = "\n"

# if only one primary key, specify it along with the column
first_pk = False
for create_column in create.columns:
column = create_column.element
try:
processed = self.process(
create_column, first_pk=column.primary_key and not first_pk
)
if processed is not None:
text += separator
separator = ", \n"
text += "\t" + processed
if column.primary_key:
first_pk = True
except exc.CompileError as ce:
util.raise_(
exc.CompileError(
util.u(f"(in table '{table.description}', column '{column.name}'): {ce.args[0]}")
),
from_=ce,
)

const = self.create_table_constraints(
table,
_include_foreign_key_constraints=create.include_foreign_key_constraints, # noqa
)
if const:
text += separator + "\t" + const

text += f"\n){self.post_create_table(table)}\n\n"
return text

[8]ページ先頭

©2009-2025 Movatter.jp