constraints

PostgreSQL constraint, that gets checked on commit and not earlier [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-04 05:26:15
问题 This question already has answers here : Constraint defined DEFERRABLE INITIALLY IMMEDIATE is still DEFERRED? (2 answers) Closed last year . Is it possible to create to create a unique index or other kind of constraint in PostgreSQL, that would be checked on transaction COMMIT and not a millisecond earlier? I need an index for a pair of (record_id, ordering), so I make sure that inside a given record_id only one and no more than one records has the same ordering. Where's the problem? Well,

Oracle trigger that check constraint on a monthly basis

五迷三道 提交于 2019-12-04 05:25:10
问题 just wonder is it possible to create a trigger to check on a specify constraint base on monthly basis. eg. table rent |ID|Member|book| ---------------------- 1 | John |fairytale| 2 | John |friction| 3 | John |comic| 4 | John |magazine| constraint : member are only allow to borrow 4 books monthly. i thought of using count(book) <= 4 but does not know how to implement the monthly basis constraint. Any suggestion? 回答1: using a trigger, whilst it seems to work, is a dangerous way of doing it, as

How to have a primary key combination that may have null values?

柔情痞子 提交于 2019-12-04 05:16:17
I have two tables A and B as defined bellow. create table A ( A_1 varchar2(10) NOT NULL, A_2 varchar2(10), A_3 varchar2(10), constraint A_PK primary key (A_1,A_2) ) TABLE A DATA A_1 |A_2 |A_3 1111 abc some_text1 1111 null some_text1 1112 abc some_text2 1113 def some_text3 create table B ( B_1 varchar2(10) NOT NULL, B_2 varchar2(10), B_3 varchar2(10), constraint B_PK primary key (B_1,B_2,B_3), constraint B_FK foreign key (B_1,B2) references A(A_1,A_2) ) TABLE B DATA B_1 | B_2 |B_3 1111 abc text1 1111 null text2 1111 null text3 1111 null text4 A_2 column in table A can sometimes be null but the

Grails 2.1 Unit Testing Command Object mockForConstraintsTests not working?

泄露秘密 提交于 2019-12-04 04:24:26
问题 I have used manually written as well as Grails generated Unit tests for this command object: package myapp @grails.validation.Validateable class SearchCommand { String basisBuild String buildToSearch static constraints = { basisBuild(blank: false) } } After having my hand written unit test fail I used Grails: create-unit-test myapp.SearchCommand I filled in the Unit Test, and made an assertion that should pass per documentation on mocked constraints: package myapp import static org.junit

“Fixed leading and trailing constraints may cause clipping” bug?

柔情痞子 提交于 2019-12-04 04:23:17
There's this other question here that addresses a similar issue, but in that case Xcode's behavior is correct, just annoying. In my case, however, I think it's actually a bug: That label can have an unlimited number of lines, so it'll never be clipped, the text will just break. It works fine with every localization: I want the label to be centered and I want the text to be at least 20 pixels away from the margins, so I set fixed constraints for the leading and trailing. Xcode wants me to change one of them to a "greater than or equal" constraint, but in that case the text won't be perfectly

Combine a PostgreSQL EXCLUDE range constraint with a UNIQUE constraint

ぐ巨炮叔叔 提交于 2019-12-04 03:36:26
In PostgreSQL, how do you combine an exclusion constraint on a range column with a unique constraint on other, scalar columns. Or to put it another way, how do I ensure that the range overlap check is only done in combination with a unique check on some other columns? For example, say I have: CREATE TABLE reservation ( restaurant_id int, time_range tsrange ); I want to make sure that for each restaurant_id , there are no overlapping time_range s. I know that I can create an exclusive range constraint like this: CREATE TABLE reservation ( restaurant_id int, time_range tsrange EXCLUDE USING gist

MySql primary key constraint with name

China☆狼群 提交于 2019-12-04 03:32:42
问题 Data definition statement: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (P_Id) ) What is the value and purpose of CONSTRAINT pk_PersonID PRIMARY KEY (P_Id) ? as opposed to this PRIMARY KEY (P_Id) ? MySql docs do not really say much about this except for this. 回答1: It's the same as MySQL ignores the CONSTRAINT pk_PersonID part. You can check by creating the table and

SWI-Prolog and constraints, library CLP(FD)

懵懂的女人 提交于 2019-12-04 03:31:49
问题 I'm playing around with constraints in (swi) prolog using the clpfd library. I'm trying to identify when one set of constraints encapsulates or subsumes the other, e.g. X<4 encapsulates X<7 as whenever the former is true, the latter is true. This can be easily represented using logical implication. However, I couldn't get the #==> operator to give me the result I wanted, so I resorted to using not(Co1 #/\ #\Co2) where Co1 and Co2 are constraints. This is fine for individual constraints, but I

Violation of Primary Key error on Identity column

无人久伴 提交于 2019-12-04 03:04:21
问题 This is maddening! Code in question has been running for over 5 years. Here's the scoop.... I am doing an INSERT...SELECT into a table with a primary key that is an identity column. I do not specify the key when I insert - SQL Server generates it as expected. I am doing the insert in a stored procedure that I call in a loop (for loop in SSIS, actually). The stored procedure will insert rows in batches (configurable). It might insert 1000 rows at a time or it might insert 50,000 - doesn't

How to specify types not allowed in a .NET Generics constraint?

☆樱花仙子☆ 提交于 2019-12-04 02:56:08
问题 Is it possible to specify a constraint on a generic class that disallows certain types? I don't know if it is possible and if it is, I am not sure what the syntax would be. Something like: public class Blah<T> where : !string { } I can't seem to find any notation that would allow such a constraint. 回答1: The closest you can get is a run-time constraint. Edit : Originally I put the run-time check in the constructor call. That's actually not optimal, as it incurs overhead on every instantiation;