Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

529
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda