Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

521
Vistas
PostgreSQL: what is the difference between 0 and (0)::smallint as default?

I'm playing around with column types and default values, and came across two columns, both smallint but with different defaults:

  1. has 0
  2. has (0)::smallint

When I change 2 to the value 1 has, both are the same and nothing seems changed. Of course, I googled to find the answer to my question, and found that :: is used for type casting. But I wonder, if it is a default value, why would you need type casting?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There is no difference, and the casting is not necessary.

# create table somesmallints (a smallint default 0, b smallint default 0::smallint, c smallint default (0)::smallint);

CREATE TABLE
# \d+ somesmallints;
                                  Table "public.somesmallints"
 Column |   Type   | Collation | Nullable |    Default    | Storage | Stats target | Description 
--------+----------+-----------+----------+---------------+---------+--------------+-------------
 a      | smallint |           |          | 0             | plain   |              | 
 b      | smallint |           |          | (0)::smallint | plain   |              | 
 c      | smallint |           |          | (0)::smallint | plain   |              | 

# select 0 = 0::smallint;
 ?column? 
----------
 t
(1 row)

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda