Today I Learned

A CCSalesPro project TwitterFollow on Twitter

4 posts about #sql

Inheritance in PostgreSQL

PostgreSQL can do inheritance:

https://www.postgresql.org/docs/current/tutorial-inheritance.html

Restrict a text column to numbers

create table only_numbers (
  my_column text not null check (my_column ~ '^[0-9]+$')
);

Disable DDL transactions with tern

You can disable DDL transactions during a migration with tern by adding the magic comment to the top of the migration file:

---- tern: disable-tx ----

create index concurrently on my_table (id);

Get constraint definition in PostgreSQL

pg_get_constraintdef can be used to get the SQL definition of a constraint.

select pg_get_constraintdef(oid) from pg_constraint where conname='users_tenant_id_fkey';
-- => FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE