Integer

2 snippets across 2 stacks — Python, SQL

Also written as to integer

PYPython

Integers & Floats

PY · Numbers
syntax
x = 42      # int
y = 3.14    # float
example
count = 1_000_000
ratio = 0.618
print(type(count), type(ratio))
print(count + ratio)
output
<class 'int'> <class 'float'>
1000000.618

Note Underscores in numeric literals are ignored and serve as visual separators. Python ints have unlimited precision.

SQLSQL

CAST / Type Conversion

SQL · String Functions
syntax
CAST(expression AS data_type)
expression::data_type  -- PostgreSQL shorthand
example
SELECT
  CAST(price AS INTEGER) AS rounded_price,
  CAST(order_date AS VARCHAR) AS date_string,
  '42'::INTEGER + 8 AS sum_pg  -- PostgreSQL only
FROM products;
output
-- rounded_price | date_string | sum_pg
-- 29             | 2025-03-15  | 50

Note CAST is ANSI standard. PostgreSQL's :: shorthand is shorter but not portable. Be careful casting — CAST('abc' AS INTEGER) will throw an error. Use TRY_CAST in SQL Server for safe conversions.