Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for user-defined data types (Sybase only) #325

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
35 changes: 33 additions & 2 deletions src/tds_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ static bool show_before_row_memory_stats = false;
static const bool DEFAULT_SHOW_AFTER_ROW_MEMORY_STATS = false;
static bool show_after_row_memory_stats = false;

static const char *DEFAULT_KEEP_UNTRANSLATABLE_TYPES = false;
static bool keep_untranslatable_types = false;

static const double DEFAULT_FDW_SORT_MULTIPLIER=1.2;

/* error handling */
Expand Down Expand Up @@ -221,6 +224,18 @@ void _PG_init(void)
NULL,
NULL,
NULL);

DefineCustomBoolVariable("tds_fdw.keep_untranslatable_types",
"Keep untranslatable data types as is when importing a foreign schema",
"Set to true to use the same named domains on the Postgres side",
&keep_untranslatable_types,
DEFAULT_KEEP_UNTRANSLATABLE_TYPES,
PGC_USERSET,
0,
NULL,
NULL,
NULL);

}

/*
Expand Down Expand Up @@ -3412,8 +3427,19 @@ tdsImportSybaseSchema(ImportForeignSchemaStmt *stmt, DBPROCESS *dbproc,
*/
appendStringInfoString(&buf,
"SELECT so.name AS table_name, "
" sc.name AS column_name, "
" st.name AS data_type, "
" sc.name AS column_name, ");

if (keep_untranslatable_types)
appendStringInfoString(&buf, " st.name AS data_type, ");
else
appendStringInfoString(&buf,
" CASE WHEN st.usertype < 100 "
" THEN st.name "
" ELSE (SELECT s1.name FROM dbo.systypes s1 WHERE s1.usertype = "
" (SELECT min(s2.usertype) FROM dbo.systypes s2 WHERE s2.type = st.type)) "
" END AS data_type, ");

appendStringInfoString(&buf,
" SUBSTRING(sm.text, 10, 255) AS column_default, "
" CASE (sc.status & 0x08) "
" WHEN 8 THEN 'YES' ELSE 'NO' "
Expand Down Expand Up @@ -3681,6 +3707,11 @@ tdsImportSybaseSchema(ImportForeignSchemaStmt *stmt, DBPROCESS *dbproc,
/* Other types */
else if (strcmp(data_type, "xml") == 0)
appendStringInfoString(&buf, " xml");
else if (keep_untranslatable_types)
{
appendStringInfoString(&buf, " ");
appendStringInfoString(&buf, data_type);
}
else
{
ereport(DEBUG3,
Expand Down