code0079
code0079

Reputation: 177

Input of length greater than 255 in postgresql rails

I have a field with datatype string in the rails Postgresql table. What happens when I enter value more than 255. Does the Postgresql cut the string to 255 characters or does it prohibits from entering?

Upvotes: 1

Views: 2300

Answers (2)

barnacle.m
barnacle.m

Reputation: 2200

As per http://www.sqlines.com/postgresql/datatypes/text

...for example, VARCHAR(255) does not allow inserting a string more than 255 characters long.

It won't truncate the string for you, and it will fail if you try to insert one.

Upvotes: 1

gr33nTHumB
gr33nTHumB

Reputation: 368

Postgres will throw an error if you try to write a value longer than the field's limit: https://www.postgresql.org/docs/9.1/datatype-character.html

Here's something you can do (with a migration) if you need bigger limits and want to control it instead of using text type:
change_column :table, :column, :string, limit: 510

Upvotes: 1

Related Questions