Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there ever reason to use string data type when using rails 6 with postgres database?

I see here that :text data type seems to perform exactly the same as :string

This comment particularly:

PostgreSQL implementation prefers text. The only difference for pg string/text is constraint on length for string. No performance differences.

Is there any good reason to ever use :string when making a rails app using a postgresql database?

like image 903
stevec Avatar asked Oct 17 '25 14:10

stevec


1 Answers

No difference in performance, difference in semantics.

Several libraries (for example simpleform) look at the data type of the field in the database and perform differently depending on it. Simple form will add a number input if it's a number, a checkbox if it's a boolean and so on. For this case, it will add a single line text field for string and a multiline text box for text.

Since there is no difference in performance, you can use either, but it's still useful to denote semantics.

like image 93
Siim Liiser Avatar answered Oct 20 '25 05:10

Siim Liiser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!