Integer के Types
smallint, integer, और bigint अलग-अलग sizes के whole numbers store करते हैं।
In this page:
Syntax
column_name smallint
column_name integer
column_name bigint
column_name SERIAL
Integer Types
smallint 2 bytes इस्तेमाल करता है (-32,768 से 32,767), integer 4 bytes (लगभग plus या minus 2.1 billion), और bigint 8 bytes (लगभग plus या minus 9.2 quintillion)।
एक value range से बाहर होने पर PostgreSQL wrap करने की बजाय एक error raise करता है। Auto-incrementing ids के लिए identity columns या serial types इस्तेमाल करें, और 2 billion से ज़्यादा हो सकने वाली ids के लिए bigint।
Note:
बहुत बड़ी हो सकने वाली tables में ids के लिए bigint इस्तेमाल करें।
उदाहरण: Integer types
shop=# SELECT 2147483647::integer AS int_max, 9223372036854775807::bigint AS bigint_max;
int_max | bigint_max
------------+---------------------
2147483647 | 9223372036854775807
(1 row)
shop=# SELECT 2147483648::integer;
ERROR: integer out of range
shop=# SELECT 7 / 2 AS int_division, 7 / 2.0 AS decimal_division, 7 % 2 AS remainder;
int_division | decimal_division | remainder
--------------+------------------+-----------
3 | 3.5000 | 1
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- overflow होने वाली ids के लिए integer इस्तेमाल करना
- silent wraparound की उम्मीद करना
- counts के लिए floating types इस्तेमाल करना
चैप्टर सारांश
- smallint 2 bytes लेता है, integer 4 bytes, bigint 8 bytes
- Out-of-range values errors raise करती हैं
- Auto ids के लिए identity इस्तेमाल करें
- सबसे narrow fitting size चुनें
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: