0

In User table the column description column is a string.

But while update that column with empty string '' using sqlalchemy alembic, It will be saved as "".

  for row in sa_session.query(Modelpackage):
            setattr(row, 'description', '')

Is there any way to saved it without double quotes "" ?

Actual Result:-

enter image description here

Expected Result:-

enter image description here

Mehadi Hassan
  • 1,160
  • 1
  • 13
  • 33
  • How sure are you about these double quotes " ? How did you check for these quotes? Many tools display some quotes when there is no content. SELECT length(description) FROM _table; -- should be 0 – Frank Heikens May 10 '22 at 14:11
  • @FrankHeikens I checked in the postgressDB, Seems It's saved it as "". instead of empty. – Mehadi Hassan May 10 '22 at 14:18
  • @snakecharmerb I used DBeaver – Mehadi Hassan May 10 '22 at 14:24
  • 1
    That tells you something about DBeaver, not about the database nor the data inside that database. Please check the length of the content, that should be zero when you put an empty string in the table. – Frank Heikens May 10 '22 at 14:26
  • SqlAlchemy is a Python based app, so try to put setattr(row, 'description', None). https://stackoverflow.com/questions/26219734/empty-values-in-a-python-list – Jesusbrother May 10 '22 at 14:29
  • @FrankHeikens I understood, But the problem is, If I want to save "test string" it should be saved without double quotes. – Mehadi Hassan May 10 '22 at 14:29
  • @Jesusbrother I tried it with setattr() but same result. – Mehadi Hassan May 10 '22 at 14:30
  • 1
    This is something a tool in your tool chain is doing as `insert into some_table values('')` will not result in `""` being saved. Something above the database is doing `'""'` to get this. – Adrian Klaver May 10 '22 at 14:37
  • 1
    @Jesusbrother passing `None` would insert `NULL` values, which are not the same as an empty string. – snakecharmerb May 10 '22 at 14:54
  • @snakecharmerb you are right. I forgot that in Python None is used as an alternative of Null – Jesusbrother May 10 '22 at 15:10
  • I am unable to reproduce your issue. [This code](https://pastebin.com/79yNjCyP) works properly for me. – Gord Thompson May 10 '22 at 21:13

0 Answers0