Delete empty rows

前端 未结 4 1541
盖世英雄少女心
盖世英雄少女心 2021-02-01 17:45

I use PostgreSQL database and in one table I have the datetime column edit_user. Some rows are blank, and these rows I would like to delete.

I tried

相关标签:
4条回答
  • 2021-02-01 17:59

    I believe that your problem is that you're checking for an empty string using double quotes instead of single quotes. Try just changing to:

    DELETE FROM table WHERE edit_user=''
    
    0 讨论(0)
  • 2021-02-01 18:04

    To delete rows empty in table

    syntax:

    DELETE FROM table_name 
    WHERE column_name IS NULL;
    

    example:

    Table name: data ---> column name: pkdno

    DELETE FROM data 
    WHERE pkdno IS NULL;
    

    Answer: 5 rows deleted. (sayso)

    0 讨论(0)
  • 2021-02-01 18:13
    DELETE FROM table WHERE edit_user IS NULL;
    
    0 讨论(0)
  • 2021-02-01 18:25

    If you are trying to delete empty spaces , try using ='' instead of is null. Hence , if your row contains empty spaces , is null will not capture those records. Empty space is not null and null is not empty space.

    Dec  Hex     Binary    Char-acter Description
    0    00  00000000      NUL        null
    
    32  20  00100000      Space       space
    

    So I recommend:

    delete  from foo_table  where bar = ''
    
    #or 
    
    delete  from foo_table  where bar = '' or bar is null 
    
    #or even better , 
    
    delete from foo_table where rtrim(ltrim(isnull(bar,'')))='';
    
    0 讨论(0)
提交回复
热议问题