How do you know when to use varchar and when to use text in sql?

This seems like a very arbitrary decision. In most cases, both can do the same thing. Limiting the length of the cook, it seems to me that you shoot in the foot, because you never know how much time you need.

Is there any specific guideline for choosing VARCHAR or TEXT for your string fields?

I will use postgresql with orm framework for sqlalchemy for python.

+3
source share
6 answers

In PostgreSQL there is no technical difference between varcharandtext

You can see the column varchar(nnn)as texta control constraint that prohibits storing larger values.

, , , varchar(nnn).

text

+6

:

, , , .

, , MD5, , , . :

  • (64 .)
  • (128 .)
  • !
+2

:

  • , , .
  • , ,

, , - varchars. , ? , , , .

+1

, . , , 255 . , , ,

0

PostgresOnline, .

TEXT PostgreSQL , , , , VARCHAR, .

0

, . 64 . ( , .) 5 .

, . : " ?" "70 ", 3000 .

VARCHAR has an 8k limit in SQL Server (I think). Most applications do not require nearly as much storage for a single column.

-1
source

Source: https://habr.com/ru/post/1785732/


All Articles