1

I'm developing rails application on Postgres. One problem that I've been experiencing is when I try to assign an empty text('') to a text column value. it only recognizes that the text I want to assign is two single quotes as text value literally.

My table schema:

   create_table :products do |t|
      t.integer :seq
      t.string :title
      t.text :description
      t.timestamps
    end

My problematic migration:

Product.create({:seq => 1, :title => 'green_cos', :description => ''})

Here is the resulting record:

enter image description here

Any advice on what I should do to get the proper empty string to be assigned? or it expects me to assign a nil value instead. Does the way it treat empty and nil text differ from other database? I used what I mentioned with SQL Server before without any problem.

1
  • 1
    What is that screenshot from? I'd guess that it is using '' to indicate an empty string and nothing to indicate NULL. Try examining your data from psql instead or load the model and see if o.description.nil? or o.description == ''. Commented Sep 23, 2012 at 7:00

1 Answer 1

2

There is no problem. The quotes are NOT part of the value or in other words they are not stored in the DB. They are only used in ruby to designate a string value (the actual value is between the quotes). pgAdmin happens to display '' for an empty string to differentiate an empty string from a NULL value. NULL values are displayed as empty cells in pgAdmin it would get confusing if an empty string also resulted in a empty cell.

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

1 Comment

you have really made it cleared that the empty value is there, but only confusing display of pgAdmin. I did check pulling data out of the model, and everything seems ok like you suggested.

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.