create database bray;
\connect bray

create table currency
(
	symbol		char(3)		primary key,
	isonum		int2		,
	name		text		not null,
	place_before	bool		not null
					default 't',
	decimals	int		not null
					default 2
					check (decimals = 0 or decimals = 2)
)
;

create table country
(
	id		char(2)		primary key
					check (id ~ '[A-Z]{2}'),
	name		text		not null,
	region		text,
	telcode		text
)
;

copy country from 'country.data';

create table europe
(
	id		char(2)		primary key
				        references country (id) match full,
	vat_prefix	char(2)		not null
)
;

copy europe from 'europe.data';

create table country_ccy
(
	country		char(2)		references country (id) match full,
	ccy		char(3)		references currency (symbol) match full,
	primary key (country, ccy)
)
;



