#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Question Insert HTML in varchar column


    Hi,

    I am trying to insert HTML into a varchar column that contains words such as AND, RANGE etc and the insert fails it looks as though it is being treated as part of the T SQL even though it is in single quotes.

    Is there a way round this please?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,784
    Rep Power
    348
    Postgres does not understand "T-SQL". Are you sure you are in the correct forum?

    If you are indeed using Postgres (and not SQL Server), then show us your SQL statement.

    My guess is that you are not properly escaping single quotes embedded in your HTML code, because this sure does work:

    Code:
    c:\psql 
    psql (9.2.3)
    Type "help" for help.
    
    postgres=> create table html_data (html varchar);
    CREATE TABLE
    Time: 673,945 ms
    postgres=> commit;
    COMMIT
    Time: 109,666 ms
    postgres=> insert into html_data (html) values ('<html><head><title>Using AND in a SQL statement</title></head><body><p>AND another RANGE</p></body></
    html>');
    INSERT 0 1
    Time: 1,992 ms
    postgres=> select *
    postgres-> from html_data;
                                                        html
    ------------------------------------------------------------------------------------------------------------
     <html><head><title>Using AND in a SQL statement</title></head><body><p>AND another RANGE</p></body></html>
    (1 row)
    
    
    Time: 83,520 ms
    postgres=>
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Sorry yes I am using Postgres and your example is what I needed as a pointer in the right direction. I need to look at the SQL a little more thanks to you I at least know that from your example I can use keywords which is what I was hoping.

    Is there an issue of inserting HTML encodings such as [& + AMP +; ?

    Thanks
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Seemed to have worked it out. Sorry but the HTML I was importing into this field is quite large. The was LED's which is now LED''s and the string was going over 1 line. Should be ok now.

IMN logo majestic logo threadwatch logo seochat tools logo