Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7706923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:13:53+00:00 2026-06-01T00:13:53+00:00

I am currently working on a solution in C# to copy database tables across

  • 0

I am currently working on a solution in C# to copy database tables across from Oracle to PostgreSQL. Everything is working great apart from one thing. When I get to copying one of my table which contains sql statements in one of its fields it falls over due to having two single quotes back to back. The SQL statements MUST remain in the table as it is being used to make another program database agnostic.

Is there a way to write the following SQL but without having the two single quotes back to back as seen near the ‘TRUE’ value near the end of the line. I have also included my code below to show how the statement is built up in C#. The column is a varchar2 in Oracle and a TEXT column in PostgreSQL.

EDIT: The sql example shown is the actual INSERT statement generated by my C# code which will then be run on the postgresql database to add a record to a table. It will be used to insert a text field, among others, that contains an sql statement in the form of a string.

INSERT INTO SQL_FACTORY_TEST (SQL_FACTORY_TEST_ID,SQL_FACTORY_DIALECT,SQL_FACTORY_QUERY_NAME,SQL_FACTORY_SQL_COMMAND,USER_NAME) 
VALUES (21, 'ORACLE', 'GET_CLUSTERS', 'SELECT CLUSTER_ID, NUM_POINTS, FEATURE_PK, A.CELL_CENTROID.SDO_POINT.X, A.CELL_CENTROID.SDO_POINT.Y, A.CLUSTER_CENTROID.SDO_POINT.X, A.CLUSTER_CENTROID.SDO_POINT.Y, TO_CHAR (A.CLUSTER_EXTENT.GET_WKT ()),  TO_CHAR (A.CELL_GEOM.GET_WKT ()), A.CLUSTER_EXTENT.SDO_SRID FROM (SELECT CLUSTER_ID, NUM_POINTS, FEATURE_PK, SDO_CS.transform (CLUSTER_CENTROID, 4326) cluster_centroid, CLUSTER_EXTENT, SDO_CS.transform (CELL_CENTROID, 4326) cell_centroid, CELL_GEOM FROM :0) a  where sdo_filter( A.CELL_GEOM, SDO_CS.transform(mdsys.sdo_geometry(2003, :1, NULL, mdsys.sdo_elem_info_array(1,1003,3),mdsys.sdo_ordinate_array(:2, :3, :4, :5)),81989)) = 'TRUE'', 'PUBLIC')

Code sample:

oleDataBaseConnection.OleExecutePureSqlQuery("SELECT * FROM " + tableName);

    if (oleDataBaseConnection.HasRows())
    {
        while (oleDataBaseConnection.NextRecord())
        {
            Dictionary<string, string> postgreSQLQueries = TypeConversion.GetQueryDictionary("POSTGRESQL");

            string postgreSQLInsertQuery;

            postgreSQLQueries.TryGetValue("INSERT", out postgreSQLInsertQuery);

            postgreSQLInsertQuery = postgreSQLInsertQuery.Replace("{0}", tableName);

            StringBuilder postgresQuery = new StringBuilder();

            postgresQuery.Append(postgreSQLInsertQuery);

            postgresQuery.Append("(");

            int columnCounter = 0;

            //add a column parameter to query for each of our columns
            foreach (KeyValuePair<string, string> t in columnData)
            {
                postgresQuery.Append(t.Key + ",");
                columnCounter++;
            }

            postgresQuery = postgresQuery.Remove(postgresQuery.Length - 1, 1);
            postgresQuery.Append(") ");

            postgresQuery.Append("VALUES (");

            //Loop through values and 

            for (int i = 0; i < columnCounter; i++)
            {
                string[] foo = new string[columnData.Count];
                columnData.Values.CopyTo(foo, 0);

                if (foo[i].ToUpper() == "TEXT")
                {
                    postgresQuery.Append("'" + oleDataBaseConnection.GetFieldById(i) + "', ");
                }
                else
                {
                    postgresQuery.Append(oleDataBaseConnection.GetFieldById(i) + ", ");
                }
            }

            postgresQuery = postgresQuery.Remove(postgresQuery.Length - 2, 2);
            postgresQuery.Append(") ");
            postgresSQLDBConnection.PostgreSQLExecutePureSqlNonQuery(postgresQuery.ToString());
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:13:54+00:00Added an answer on June 1, 2026 at 12:13 am

    The best solution is to use a PreparedStatement where you don’t pass literals directly. I don’t know C#, so I can’t give you an example for that.

    However if you have to keep the statement like that, you can use a “dollar quoted” string literal in PostgreSQL.

    INSERT INTO SQL_FACTORY_TEST (SQL_FACTORY_TEST_ID,SQL_FACTORY_DIALECT,SQL_FACTORY_QUERY_NAME,SQL_FACTORY_SQL_COMMAND,USER_NAME) 
    VALUES (21, 'ORACLE', 'GET_CLUSTERS', $$ ...... 'TRUE'$$, 'PUBLIC')
    

    The $$ replaces the single quote(s) around the literal. If there is a chance that your value contains $$ you can also add some unique identifier to it, e.g.

    $42$String with embedded single quotes ''' and two $$ dollar characters$42$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using Extension:Push to copy articles from one MediaWiki (1.16) installation (which sits
I'm currently working on a solution which needs to use both Silverlight 3.0 and
I'm currently working on a Lotus Notes solution. We're just using Web forms so
I'm currently working on an Asp.net MVC Web application. In my solution, there're two
Currently working with NSURLConnection. Found a great website showing important delegate methods coming with
I am currently working on a PHP application which is ran from the command
I'm currently working with WatiN, and finding it to be a great web browsing
I am working on a solution that loads SharePoint pages in a copy of
Currently working in the deployment of an OFBiz based ERP, we've come to the
Currently working on a VBScript to automate some of the dirty PST ingestion work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.