Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

525
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!