Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What difference between NULL and NULL::character varying in PostgreSQL

Is there a difference between default values of column in PostgreSQL? Whether this is important?

state character varying(255) DEFAULT NULL

and

state character varying(255) DEFAULT NULL::character varying
like image 511
accessd Avatar asked Jul 23 '14 13:07

accessd


People also ask

What is the difference between character and character varying in PostgreSQL?

In PostgreSQL basically varying is the alias name of varchar, so there is only one difference between character varying and varchar is character varying more friendly than varchar in PostgreSQL.

What is character varying data type in PostgreSQL?

2) PostgreSQL Varchar Data Type. The PostgreSQL Varchar data type is used to store characters of indefinite length based on the parameter n. It can store a string up to 65,535 bytes long. In the PostgreSQL Varchar data type i. e. Varchar(n), n is used to denote the character length limit.

What is :: text in PostgreSQL?

PostgreSQL supports a character data type called TEXT. This data type is used to store character of unlimited length. It is represented as text in PostgreSQL. The performance of the varchar (without n) and text are the same. Syntax: variable_name TEXT.

What is character varying data type?

The CHARACTER VARYING data type stores a string of letters, digits, and symbols of varying length, where m is the maximum size of the column (in bytes) and r is the minimum number of bytes reserved for that column.


1 Answers

There is no effective difference in the presented example in a standard installation.

Without explicit cast, NULL of data type unknown will be coerced to varchar in an assignment cast automatically. See:

  • Generate series of dates - using date type as input

In other situations, where the type cannot be derived from context, you may need to cast explicitly - to tell Postgres the intended type of the value. This is rarely the case, though.

like image 176
Erwin Brandstetter Avatar answered Oct 19 '22 06:10

Erwin Brandstetter