TOPIC: Suneido equivalent of SQL check constraints
#1686
Suneido equivalent of SQL check constraints 8 Months, 3 Weeks ago
I'm trying to import a table in suneido from postgresql but I don't know how to make the constraints in suneido:

CREATE TABLE testtree
(
id serial NOT NULL,
parent_id integer,
CONSTRAINT testtree_pkey PRIMARY KEY (id),
CONSTRAINT testtree_fk_parent_id FOREIGN KEY (parent_id)
REFERENCES testtree (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT testtree_chk_parent CHECK (parent_id <> id)
)

create testtree(id, parent_id)
key(id)
index(parent_id) in testtree(id)


Also I created the following rule to try prevent circular references:

parent_id_deps
function()
{
return not (.parent_id is .id)
}

And then tested with:

insert {id:1 } into testtree

insert {id:2, parent_id:1 } into testtree

insert {id:3, parent_id:1 } into testtree

update testtree where id is 3 set parent_id = 3
//the above succeeded but it shouldnt

Can someone tell me how to achieve this ?
 
 
#1689
Re:Suneido equivalent of SQL check constraints 8 Months, 3 Weeks ago
Suneido does not have constraints (other than foreign key and uniqueness).

_deps is for rule dependencies, not for constraints.

One possibility might be to check in a trigger and throw an exception.
 
 
andrew