unique-constraint

ORM UniqueConstraint, null value duplicate

守給你的承諾、 提交于 2019-12-07 10:08:20
问题 I have an entity with an unique constraint on 3 fiels. 2 fields are not nullable, and the third is nullable. My problem, when the third field is null, the unique constraint doesn't work, so i can have in my database some duplicate values like ( 5,1,null)(5,1,null) For me, ( 5,1,null) is an unique value, with null too. Do you have any ideas ? This is my ORM line : * @ORM\Table(name="table", uniqueConstraints={@ORM\UniqueConstraint(name="table_idx", columns={"field1", "field2", "field3"})})

Increment field with not null and unique constraint in PostgreSQL 8.3

和自甴很熟 提交于 2019-12-07 09:18:19
问题 I have a table "items" with a column "position". position has a unique and not-null constraint. In order to insert a new row at position x I first try increment the positions of the subsequent items: UPDATE items SET position = position + 1 WHERE position >= x; This results in a unique constraint violation: ERROR: duplicate key value violates unique constraint The problem seems to be the order in which PostgreSQL performs the updates. Unique constraints in PostgreSQL < 9.0 aren't deferrable

Why is Fluent NHibernate ignoring my unique constraint on a component?

匆匆过客 提交于 2019-12-07 06:19:53
问题 In my map I have: Component( x => x.ExposureKey, m => { m.Map(x => x.AsOfDate).Not.Nullable(); m.Map(x => x.ExposureId).Length(30).Not.Nullable(); } ).Unique(); The relevant output from the HBM is <component name="ExposureKey" insert="true" update="true" optimistic-lock="true" class="Some.Namespace.CreditExposureKey, Some.Namespace, Version=0.0.0.0, Culture=neutral, PublicKeyToken=aaaaaaaaaaaaaaaa"> <property name="AsOfDate" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral,

Storing and comparing unique combinations

感情迁移 提交于 2019-12-07 02:55:29
I need search functionality on a website where among other things you should be able to select multiple categories. The searches will be stored in the database but each unique combination of search parameters should only be stored once, this also includes the unique combination of selected categories. The problem is that I cannot figure out how to store the combinations of selected categories. I have looked at arrays and found this http://blog.2ndquadrant.com/postgresql-9-3-development-array-element-foreign-keys/ but apparently that feature was never implemented. So if I need to use multiple

Django custom unique together constraint

一世执手 提交于 2019-12-07 02:13:16
问题 I have a users share model something like below: class Share( models.Model ): sharer = models.ForeignKey(User, verbose_name=_("Sharer"), related_name='sharer') receiver = models.ForeignKey(User, verbose_name=_("Receiver"), related_name='receiver') class Meta: unique_together = ( ("sharer", "receiver"), ("receiver", "sharer") ) I want to save a single object for sharer(S) and receiver(R) (order doesn't matters R-S or S-R). but above unique_together will not fulfil this; Suppose R-S is in

Multi-Column Unique Constraint with web2py

喜你入骨 提交于 2019-12-06 23:35:16
问题 It is possible to mark a particular column as unique=true. What is the most correct way to handle multi-column unique constraints in web2py? For example, say I have an exchange rate table. It could have columns from-currency, to-currency and the exchange rate. It would not make sense to have two rows with the same from and to currencies. What would be the most elegant or correct way to make the from/to combination unique? 回答1: Assuming the data will be entered via a form, you could use a form

How to specify that a combination of columns should be a unique constraint using annotations?

核能气质少年 提交于 2019-12-06 19:10:43
问题 I want to make sure that all rows in my table have a unique combination of two fields, and I want to specify this using annotations in my entity class. I have tried using a combination of @Table and @UniqueConstraint but apparently I'm doing it wrong, in that I can only seem to specify that the separate columns should be unique (I can already specify that using the @Column's unique property) rather than a combination of columns. For example I want a table which has fields A and B to contain

ORA-00001: unique constraint primary key violated

杀马特。学长 韩版系。学妹 提交于 2019-12-06 14:01:41
问题 DELETE from dbo.T_LIAV_AGENT_STATE_APPROVAL SAP WHERE EXISTS (SELECT UNIQUE 1 FROM MCS_SYNC_STATE_APPR APP inner join MCS_SYNC_NAME SN on SN.SE_NAME_ID = APP.SE_NAME_ID and SN.ACTION in('U','S') Where APP.SE_name_id = SAP.AV_NAME_ID and APP.SYNC_INSTANCE_ID = param_inst_ID); COMMIT; INSERT INTO dbo.T_LIAV_AGENT_STATE_APPROVAL SELECT UNIQUE APP.SE_NAME_ID AS AV_NAME_ID, APP.STATE AS AV_STATE, APP.APPROVAL_TYPE AS AV_APPROVAL_TYPE, APP.START_DATE AS AV_START_DATE, APP.END_DATE AS AV_END_DATE,

Unique Index over postgresql partitions

▼魔方 西西 提交于 2019-12-06 11:58:16
问题 I have table call it cdrs: CREATE TABLE cdrs ( i_cdr bigint NOT NULL, i_cdrs_connection bigint NOT NULL, i_call bigint NOT NULL, customer_name character varying(156) NOT NULL, client_name_id character varying(256) NOT NULL, connection_name character varying(156) NOT NULL, vendor_name_id character varying(256) NOT NULL, setup_time timestamp with time zone NOT NULL, c_result_id bigint NOT NULL, v_result_id bigint NOT NULL ); Now Created partitions using inherit by trigger on insert to parent

Hibernate ConstraintViolationException on SELECT query

非 Y 不嫁゛ 提交于 2019-12-06 11:01:19
I have a Persistent Class with multi-field unique constraint on it. But defined unique constraint is not sufficient for me because on one those field non-equal but similar values are unique too. I implement a checkUniqueConstraint method. In add and update methods of DAO class, I call checkUniqueConstraint before adding or updating persist object. checkUniqueConstraint method just run a SELECT query to find object similar to input and throw a check Exception where find some ones. public class PersistClassDao { public void checkUniqueConstraint(PersistClass persistObject) throws