Created
December 24, 2014 14:16
-
-
Save daniel70/7b20d55a4be6d4701389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create extension if not exists hstore | |
drop table public.product; | |
create table public.product ( | |
id serial, | |
nr int not null, | |
name varchar(100) not null, | |
names hstore null, | |
growing_months int[] null constraint valid_month check (growing_months <@ ARRAY[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), | |
season daterange null | |
) | |
create or replace function default_language() | |
returns trigger as | |
$BODY$ | |
begin | |
NEW.names = COALESCE(NEW.names, '') || hstore('en', NEW.name); | |
return NEW; | |
end; | |
$BODY$ | |
language plpgsql; | |
create trigger i_product_name before insert on public.product for each row execute procedure default_language(); | |
create trigger u_product_name before update on public.product for each row when (OLD.name IS DISTINCT FROM NEW.name) execute procedure default_language(); | |
insert into public.product (nr, name, names, growing_months, season) values (847, 'Bicycle', ('nl => Fiets')::hstore, ARRAY[1, 2, 11, 12], '[2014-01-04, 2014-05-06]') | |
select * from product | |
update product set name = 'Bycicle' where id = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment