unique-constraint

Is there a way to enforce unique constraint on a property (field) other than the primary key in dynamodb

此生再无相见时 提交于 2019-11-27 20:23:50
In dynamodb, if you want to enforce uniqueness in a field other than the primary key (like were you have a users table and want unique email addresses for users while primary key is a userid which is a number) is there a way other thans scanning the table to see if the email is already in use? Short answer: No. DynamoDB is a key:value store. It is very good at quickly retrieving/saving Items because it does a couple of compromise. This is a constraint you have to handle yourself. Nonethess, depending on your actual model, it might be a good idea to use this field as you hash_key or consider

Django - save() update on duplicate key

大憨熊 提交于 2019-11-27 19:18:11
问题 I have little application which allows a user to rate a video. The user can rate only once. So I have defined the uniqueness on the model. But he should be able change his rate. So the save() should update on duplicate key class VideoRate(models.Model): """Users can Rate each Video on the criterias defined for the topic""" user = models.ForeignKey(User) video = models.ForeignKey(VideoFile) crit = models.ForeignKey(VideoCrit) rate = models.DecimalField(max_digits=2, decimal_places=1, choices

Create Unqiue case-insensitive constraint on two varchar fields

风格不统一 提交于 2019-11-27 18:18:16
问题 In Oracle 10g, how do I add a unique case-insensitive constraint on two varchar fields? For example, given the following records already in the table: "Stephen", "Swensen" "John", "Smith" The following inserts would be invalid: "stephen", "Swensen" "John", "smith" "stephen", "swensen" But the following inserts would be valid: "Stephen", "Smith" "John", "Swensen" 回答1: Assuming your table is called person , and the first and last name columns are called first_name and last_name , add this

How do you validate uniqueness of a pair of ids in Ruby on Rails?

ε祈祈猫儿з 提交于 2019-11-27 18:17:52
Suppose the following DB migration in Ruby: create_table :question_votes do |t| t.integer :user_id t.integer :question_id t.integer :vote t.timestamps end Suppose further that I wish the rows in the DB contain unique (user_id, question_id) pairs. What is the right dust to put in the model to accomplish that? validates_uniqueness_of :user_id, :question_id seems to simply make rows unique by user id, and unique by question id, instead of unique by the pair. validates_uniqueness_of :user_id, :scope => [:question_id] if you needed to include another column (or more), you can add that to the scope

Does a Postgres UNIQUE constraint imply an index?

瘦欲@ 提交于 2019-11-27 16:09:49
When adding a unique constraint to a Postgres table does that imply that an index has also been added to that table? Meaning, if I add a UNIQUE constraint on a text column, does that text column now have an index or does an index have to be added separately? Erwin Brandstetter Yes. UNIQUE constraints are implemented using a btree index in Postgres. Details: How does PostgreSQL enforce the UNIQUE constraint / what type of index does it use? 来源: https://stackoverflow.com/questions/29655439/does-a-postgres-unique-constraint-imply-an-index

How to give a unique constraint to a combination of columns in Oracle?

心不动则不痛 提交于 2019-11-27 15:32:20
问题 I have a Table with 4 Columns Each Column will be A,B,C,D Column A is the Primary key. Column B has unique name constraint. Now I want to remove the unique constraint for column B and give a unique constraint by combining the columns B, C and D. So the table will allow only one row with a particular value in columns B,C and D. How can I give this type of a constraint? I tried giving the composite unique key like : ALTER TABLE TABLENAME ADD CONSTRAINT CONSTRAINT_NAME UNIQUE (COLUMN_B, COLUMN_C

SQL Unique constraint across multiple tables

依然范特西╮ 提交于 2019-11-27 14:37:06
I am trying to create a unique constraint across multiple tables. I have found similar questions answered here but they don't quite capture the spirit of what I am trying to do. As an example, I have three tables, t_Analog, t_Discrete, t_Message CREATE TABLE t_Analog( [AppName] [nvarchar](20) NOT NULL, [ItemName] [nvarchar](32) NOT NULL, [Value] [float] NOT NULL, CONSTRAINT [uc_t_Analog] UNIQUE(AppName, ItemName) ) CREATE TABLE t_Discrete( [AppName] [nvarchar](20) NOT NULL, [ItemName] [nvarchar](32) NOT NULL, [Value] [bit] NOT NULL, CONSTRAINT [uc_t_Discrete] UNIQUE(AppName, ItemName) ) CREATE

UNIQUE constraint failed: sqlite database : android

戏子无情 提交于 2019-11-27 13:41:39
问题 I am trying to insert values in table. But there is only one value inserted. I am getting an error in log cat when I am trying to insert new values. Log cat shows : abort at 13 in [INSERT INTO event(totalminutesfrom,dayofweek,title,location,totalminutesto,id) VALUES (?,?,?,?,?,?)]: UNIQUE constraint failed: event.id 01-24 11:34:39.764 7763-7763/com.example.siddhi.timetablelayout E/SQLiteDatabase: Error inserting totalminutesfrom=694 dayofweek=null title=qxs location=Eded & Mariz

Grails domain class: unique constraint for multiple columns

扶醉桌前 提交于 2019-11-27 12:40:34
问题 Suppose a simple Grails domain class: class Account { String countryId; String userName; String password; static constraints = { ...???... } } It is required that user names are unique for a particular countryId , thus there must be a unique contraint on two columns. How to express this in the constraints definition? 回答1: userName(unique: ['countryId']) You can include as many other properties in the array that make up the other properties that must be considered in the "unique" constraint on

Unique index or unique key?

纵饮孤独 提交于 2019-11-27 11:54:43
问题 What is the diffrence between a unique index and a unique key? 回答1: The unique piece is not where the difference lies. The index and key are not the same thing, and are not comparable. A key is a data column, or several columns, that are forced to be unique with a constraint, either primary key or explicitly defined unique constraint. Whereas an index is a structure for storing data location for faster retrieval. From the docs: Unique Index Creates a unique index on a table or view. A unique