DatabaseStatusSyntax FamilyMin Version
PostgreSQL full - -
MySQL none - -
MariaDB none - -
Oracle none - -
SQL Server none - -
SQLite none - -
Redshift none - -
DB2 none - -
Snowflake none - -
BigQuery none - -

Compare Databases

Database Details

PostgreSQL full
-- inet: host address (IPv4 or IPv6, with optional prefix length)
CREATE TABLE hosts (
  id        SERIAL PRIMARY KEY,
  ip        inet    NOT NULL,
  network   cidr,
  mac_addr  macaddr
);

INSERT INTO hosts (ip, network, mac_addr)
VALUES
  ('192.168.1.100', '192.168.1.0/24', '08:00:2b:01:02:03'),
  ('2001:db8::1',   '2001:db8::/32',  '08:00:2b:01:02:04');

-- Containment: is the host in this subnet?
SELECT ip FROM hosts WHERE ip << '192.168.1.0/24';

-- Supernet check
SELECT ip FROM hosts WHERE '192.168.1.0/24' >>= ip;

-- Useful functions
SELECT
  host(ip)        AS host_part,
  network(ip)     AS network_part,
  broadcast(ip)   AS broadcast,
  netmask(ip)     AS netmask,
  masklen(ip)     AS prefix_len,
  abbrev(ip)      AS abbreviated,
  family(ip)      AS ip_family  -- 4 or 6
FROM hosts;

-- macaddr8 for EUI-64
CREATE TABLE interfaces (mac macaddr8);

-- Address arithmetic
SELECT '192.168.1.1'::inet + 5;   -- 192.168.1.6
SELECT '192.168.1.20'::inet - '192.168.1.1'::inet;  -- 19
  • inet accepts IPv4 and IPv6 addresses with an optional CIDR prefix length (e.g., 192.168.1.100/24).
  • cidr requires that host bits be zero; use it for network block storage (e.g., 192.168.1.0/24).
  • macaddr stores 6-byte Ethernet MAC addresses. macaddr8 (PostgreSQL 10+) stores 8-byte EUI-64 MAC addresses.
  • Operators: < <= = >= > <> (ordering), << (contained by subnet), <<= (contained or equal), >> (contains subnet), >>= (contains or equal), && (overlap), ~ (bitwise NOT), & (bitwise AND), | (bitwise OR), + (add integer), - (subtract).
  • Functions: abbrev(), broadcast(), family(), host(), hostmask(), inet_merge(), inet_same_family(), masklen(), netmask(), network(), set_masklen().
  • GiST and GIST indexes support subnet containment queries efficiently.
  • macaddr functions: trunc() zeros the last 3 bytes; useful for OUI prefix matching.
MySQL none
-- Workaround: store IPv4 as BIGINT UNSIGNED
CREATE TABLE hosts (
  id    INT AUTO_INCREMENT PRIMARY KEY,
  ip_v4 BIGINT UNSIGNED,  -- use INET_ATON/INET_NTOA
  ip    VARCHAR(45)        -- for IPv6 or mixed
);

-- Convert IPv4 string to integer and back
SELECT INET_ATON('192.168.1.100') AS ip_int;   -- 3232235876
SELECT INET_NTOA(3232235876) AS ip_str;        -- 192.168.1.100

-- IPv6 binary storage and conversion
SELECT INET6_ATON('2001:db8::1') AS ip_bin;    -- VARBINARY(16)
SELECT INET6_NTOA(INET6_ATON('2001:db8::1')) AS ip_str;

-- Subnet check (manual bit math for IPv4)
SELECT ip FROM hosts
WHERE INET_ATON(ip) BETWEEN INET_ATON('192.168.1.0') AND INET_ATON('192.168.1.255');
  • No native IP address types.
  • INET_ATON() / INET_NTOA() convert IPv4 strings to/from unsigned integers.
  • INET6_ATON() / INET6_NTOA() convert IPv4 and IPv6 strings to/from VARBINARY(16).
  • IS_IPV4(), IS_IPV6(), IS_IPV4_MAPPED(), IS_IPV4_COMPAT() validate address format.
  • Subnet/CIDR operations require manual bit arithmetic.
MariaDB none
-- Same INET6_ATON/INET6_NTOA approach as MySQL
SELECT INET6_ATON('192.168.1.100') AS ip_bin;
SELECT INET6_NTOA(INET6_ATON('192.168.1.100')) AS ip_str;

-- IS_IPV4 / IS_IPV6 for validation
SELECT IS_IPV6('2001:db8::1');
  • No native IP address types.
  • Same INET_ATON/NTOA and INET6_ATON/NTOA functions as MySQL.
  • Subnet operations require manual bit arithmetic.
Oracle none
-- Workaround: store as VARCHAR2
CREATE TABLE hosts (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  ip VARCHAR2(45)
);

-- UTL_INADDR functions for DNS/IP lookups
SELECT UTL_INADDR.GET_HOST_ADDRESS('example.com') FROM DUAL;
SELECT UTL_INADDR.GET_HOST_NAME('93.184.216.34') FROM DUAL;
  • No native IP address types.
  • Store as VARCHAR2(45) for IPv6 compatibility.
  • UTL_INADDR package provides DNS forward/reverse lookups but no IP arithmetic.
  • CIDR/subnet operations require custom PL/SQL functions.
SQL Server none
-- Workaround: store as VARCHAR(45) or VARBINARY(16)
CREATE TABLE hosts (
  id  INT IDENTITY(1,1) PRIMARY KEY,
  ip  VARCHAR(45) NOT NULL
);

-- Validate IPv4 format with a CHECK constraint
ALTER TABLE hosts ADD CONSTRAINT chk_ip
  CHECK (ip LIKE '[0-9]%.%' OR ip LIKE '%:%');  -- rough check

-- Subnet containment requires CLR function or manual T-SQL
  • No native IP address types.
  • Use VARCHAR(45) to store both IPv4 and IPv6 addresses.
  • IP arithmetic and subnet operations require CLR (C#) user-defined functions or manual T-SQL bit math.
  • No built-in IP validation or conversion functions.
SQLite none
-- Workaround: store as TEXT
CREATE TABLE hosts (
  id  INTEGER PRIMARY KEY,
  ip  TEXT NOT NULL
);

-- No built-in IP functions; validate and operate in application code.
  • No network address types or IP functions.
  • Store as TEXT and perform all validation and operations in application code.
Redshift none
-- Workaround: store as VARCHAR
CREATE TABLE hosts (
  id  INTEGER IDENTITY(1,1) PRIMARY KEY,
  ip  VARCHAR(45) NOT NULL
);
  • No network address types or IP functions.
  • Store as VARCHAR(45) and perform operations in application or ETL code.
DB2 none
-- Workaround: store as VARCHAR
CREATE TABLE hosts (
  id  INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  ip  VARCHAR(45) NOT NULL
);
  • No native network address types.
  • Store as VARCHAR and use application code for IP arithmetic and subnet operations.
Snowflake none
-- Workaround: store as VARCHAR
CREATE TABLE hosts (
  id  INTEGER AUTOINCREMENT PRIMARY KEY,
  ip  VARCHAR(45) NOT NULL
);
  • No native network address types.
  • Store as VARCHAR and perform IP operations in application code or JavaScript UDFs.
BigQuery none
-- Workaround: store as STRING
CREATE TABLE dataset.hosts (
  id  INT64,
  ip  STRING
);

-- NET functions for IP manipulation
SELECT
  NET.IP_FROM_STRING('192.168.1.100') AS ip_bytes,          -- BYTES
  NET.IP_TO_STRING(NET.IP_FROM_STRING('192.168.1.100')) AS ip_str,
  NET.IPV4_FROM_INT64(3232235876) AS ip_from_int,
  NET.IPV4_TO_INT64(NET.IP_FROM_STRING('192.168.1.100')) AS ip_to_int,
  NET.IP_IN_NET('192.168.1.100', '192.168.1.0/24') AS in_subnet,
  NET.MAKE_NET('192.168.1.100', 24) AS cidr_block;
  • No native network address types.
  • Store as STRING for display; use BYTES for efficient binary storage.
  • NET functions provide IP manipulation: NET.IP_FROM_STRING(), NET.IP_TO_STRING(), NET.IP_IN_NET(), NET.MAKE_NET(), NET.IPV4_FROM_INT64(), NET.IPV4_TO_INT64(), NET.HOST(), NET.PUBLIC_SUFFIX(), NET.REG_DOMAIN().
  • NET.IP_IN_NET() is the closest equivalent to PostgreSQL's << operator for subnet containment.