constraints

Using Postgres domains to simplify function input validation

巧了我就是萌 提交于 2021-02-10 20:46:24
问题 Using Postgres 11.5, I've been looking at CREATE DOMAIN since yesterday, and would like to clarify how they can/can't help with function parameters. Ideally, I'd like to use a domain to screen parameter inputs easily, but with a helpful error response. As an example, I'm using a simple first-case, a domain that blocks null and empty strings: CREATE DOMAIN text_not_empty AS text NOT NULL CHECK (value <> ''); I tried this out as a field type for a table, and it's great. When we don't allow

Using Postgres domains to simplify function input validation

霸气de小男生 提交于 2021-02-10 20:45:06
问题 Using Postgres 11.5, I've been looking at CREATE DOMAIN since yesterday, and would like to clarify how they can/can't help with function parameters. Ideally, I'd like to use a domain to screen parameter inputs easily, but with a helpful error response. As an example, I'm using a simple first-case, a domain that blocks null and empty strings: CREATE DOMAIN text_not_empty AS text NOT NULL CHECK (value <> ''); I tried this out as a field type for a table, and it's great. When we don't allow

Foreign key reference target does not exist

我们两清 提交于 2021-02-10 16:57:22
问题 I need to synchronize data in two tables from different Firebird databases. Precisely, I need to update records in table Person (1st DB), using records from table Users (2nd DB). Not only "name", "email", "birthday", but ID also (!). The problem is - there are tables, that depend on Person's IDs through FOREIGN KEY Constraint. I'm trying to do this: Drop Foreign Key constraints in dependent tables. Sync two tables (which means renewing/changing IDs in table Person) Change appropriate IDs in

Implementing Django 2.2 database constraint across multiple columns

五迷三道 提交于 2021-02-10 14:24:49
问题 I have a Django model with start date/time and end date/time where all four components may (independently) be a null value (and there is a semantic difference between a null/unknown value and a known value). I am trying to implement a database constraint [1, 2] to check that if they are non-null that the start date/time is before the end date/time. I have implemented the constraint in two different ways (commented as Option 1, a single constraint, and Option 2, as two constraints) below: from

Implementing Django 2.2 database constraint across multiple columns

▼魔方 西西 提交于 2021-02-10 14:23:59
问题 I have a Django model with start date/time and end date/time where all four components may (independently) be a null value (and there is a semantic difference between a null/unknown value and a known value). I am trying to implement a database constraint [1, 2] to check that if they are non-null that the start date/time is before the end date/time. I have implemented the constraint in two different ways (commented as Option 1, a single constraint, and Option 2, as two constraints) below: from

Implementing Django 2.2 database constraint across multiple columns

时间秒杀一切 提交于 2021-02-10 14:23:03
问题 I have a Django model with start date/time and end date/time where all four components may (independently) be a null value (and there is a semantic difference between a null/unknown value and a known value). I am trying to implement a database constraint [1, 2] to check that if they are non-null that the start date/time is before the end date/time. I have implemented the constraint in two different ways (commented as Option 1, a single constraint, and Option 2, as two constraints) below: from

Card distribution with constraints

拟墨画扇 提交于 2021-02-10 08:07:00
问题 Suppose I would like to distribute a deck of 52 cards unto N players , not necessarily equally so each player Pi would get a number of cards Ci . Suppose that each of these players might have constraints that dictate what cards (s)he can receive, for example Player P2 cannot get any cards in the Hearts color and P5 cannot get any cards above 10. All these constraints are guaranteed to have at least one distribution/solution. My main question is how would one go about this programmatically?

Card distribution with constraints

六眼飞鱼酱① 提交于 2021-02-10 08:05:34
问题 Suppose I would like to distribute a deck of 52 cards unto N players , not necessarily equally so each player Pi would get a number of cards Ci . Suppose that each of these players might have constraints that dictate what cards (s)he can receive, for example Player P2 cannot get any cards in the Hearts color and P5 cannot get any cards above 10. All these constraints are guaranteed to have at least one distribution/solution. My main question is how would one go about this programmatically?

Is there a safe way to modify the table pg_constraint so as no more checking be done ( temporarily )?

旧巷老猫 提交于 2021-02-08 06:11:56
问题 So as to restore a database from a dump, I want to temporarily disable all the constraints in all the tables of my database, which content I have emptied ( postregsql 8.3). Is there a safe way to modify a field in the pg_constraint table that easily allows to bypass the constraint ? I don't think so when I look at the documentation pg_constraint. Is it possible to drop the pg_constraint table content, then refill it again ? If not, how people do restore/copy databases with tables that are

Is there a safe way to modify the table pg_constraint so as no more checking be done ( temporarily )?

橙三吉。 提交于 2021-02-08 06:11:44
问题 So as to restore a database from a dump, I want to temporarily disable all the constraints in all the tables of my database, which content I have emptied ( postregsql 8.3). Is there a safe way to modify a field in the pg_constraint table that easily allows to bypass the constraint ? I don't think so when I look at the documentation pg_constraint. Is it possible to drop the pg_constraint table content, then refill it again ? If not, how people do restore/copy databases with tables that are