0

I am tasked with migrating some databases from Postgres to MS SQL Server.

I was trying to use the SQL Server Import and Export Wizard as per the link here, https://learn.microsoft.com/en-us/sql/integration-services/import-export-data/connect-to-a-postgresql-data-source-sql-server-import-and-export-wizard?view=sql-server-ver15.

I was selecting: "SQL Server Native Client 11.0" as the Destination, and "Copy data from one or more tables or views".

I am trying to migrate the data into an existing table.

However when I try and do a migration I get the following error:

Migration Error

I am not a DBA and my Postgres and SQL skills are mediocre at best, so any advice would be greatly appreciated!

2
  • I'm guessing you need to spend some time here Column mapping. Commented Mar 20, 2021 at 15:39
  • It seems the ODBC meta data isn't mapping as expected. See this question and blog post. The location of the ProviderDescriptors.xml file is probably under your SSMS installation folder. Commented Mar 20, 2021 at 15:41

1 Answer 1

0

The meta data returned by the PostgreSQL ODBC driver isn't mapped correctly by the SSMS ProviderDescriptors.xml file. This file is located in directory "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\CommonExtensions\Microsoft\SSIS\150\ProviderDescriptors" on my SSMS installation.

Using information gleaned from this question and MS blog post, I was able to successfully import from PostgreSQL with the System.Data.Odbc.OdbcConnection ProviderDescriptor config section below. I changed the MaximumLengthColumnName, NumericPrecisionColumnName, and NumericScaleColumnName attribute values in the System.Data.Odbc.OdbcConnection ColumnSchemaAttributes to match the actual names returned by the PosgreSQL ODBC driver (LENGTH, and PRECISION, SCALE).

<dtm:ProviderDescriptor SourceType="System.Data.Odbc.OdbcConnection">

    <dtm:SchemaNames
        TablesSchemaName="Tables"
        ColumnsSchemaName="Columns" 
        ViewsSchemaName="Views" 
    />

    <dtm:TableSchemaAttributes
        TableCatalogColumnName="TABLE_CAT"
        TableSchemaColumnName="TABLE_SCHEM"
        TableNameColumnName="TABLE_NAME"
        TableTypeColumnName="TABLE_TYPE"
        TableDescriptor="TABLE"
        ViewDescriptor="VIEW"
        SynonymDescriptor ="SYNONYM"
        NumberOfTableRestrictions="3"
    />

    <dtm:ColumnSchemaAttributes
        NameColumnName = "COLUMN_NAME"
        OrdinalPositionColumnName="ORDINAL_POSITION"
        DataTypeColumnName = "TYPE_NAME"
        MaximumLengthColumnName = "LENGTH"
        NumericPrecisionColumnName = "PRECISION"
        NumericScaleColumnName = "SCALE"
        NullableColumnName="NULLABLE"
        NumberOfColumnRestrictions="4"
    />

    <dtm:Literals
        PrefixQualifier="&quot;"
        SuffixQualifier="&quot;"
        CatalogSeparator="."
        SchemaSeparator="."
    />
</dtm:ProviderDescriptor>

You may want to save the original ProviderDescriptors.xml file and revert back to it once your import tasks are completed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.