Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

In Postgres, is it possible for me to have a table partitioning constraint based on data type?

$
0
0

Say I have the following schema for my Postgres database:

CREATE TABLE sources (
  source  TEXT  NOT NULL,
  PRIMARY KEY (source)
);

CREATE TABLE ipaddrs (
  addr  INET
) INHERITS (source):

CREATE TABLE domains (
  domain  TEXT
) INHERITS (source);

Is it possible for me to use a CHECK constraint somewhere that would add a source that is a valid IP address to the ipaddrs partition, and otherwise add it to the domains partition?

Ultimately, I’m wanting to be able to leverage Postgres’ built-in INET/CIDR capabilities on sources that are IP addresses.


Viewing all articles
Browse latest Browse all 1138

Trending Articles