473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

add constraints to views

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Please consider the following situation.

CREATE TABLE test_table (
~ id SERIAL PRIMARY_KEY,
~ tag BOOLEAN,
~ field1 INTEGER
);

CREATE VIEW test_view (
~ SELECT * FROM test_table WHERE tag
);

Now I want ad a NOT NULL constraint to the view on field1. I tryed the
following, but neither works.

ALTER TABLE test_view ADD CONSTRAINT isit CHECK ( field1 IS NOT NULL);
ALTER TABLE test_view ALTER field1 SET NOT NULL;

How can I do this?

Regards

Andreas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Debian - http://enigmail.mozdev.org

iD8DBQE/bCnEPkvkZVZzNY0RAgiBAKChAPbr+RV1bTYX5+2vnCg/KU6k5ACfeGmd
/tbh47tLhPee5mAkFLzODZU=
=LDWj
-----END PGP SIGNATURE-----

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #1
3 4171
Andreas Fromm wrote:
CREATE VIEW test_view (
~ SELECT * FROM test_table WHERE tag
);

Now I want ad a NOT NULL constraint to the view on field1. I tryed the
following, but neither works.


what does mean add a null constrain to a view ? Do you mean
filter out the records with the field1 null ?

CREATE OR REPLACE test_view AS
SELECT *
FROM test_table
WHERE field1 IS NOT NULL AND
tag;
Regards
Gaetano Mendola
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gaetano Mendola wrote:
| Andreas Fromm wrote:
|
|> CREATE VIEW test_view (
|> ~ SELECT * FROM test_table WHERE tag
|> );
|>
|> Now I want ad a NOT NULL constraint to the view on field1. I tryed the
|> following, but neither works.
|
|
| what does mean add a null constrain to a view ? Do you mean
| filter out the records with the field1 null ?
|
| CREATE OR REPLACE test_view AS
| SELECT *
| FROM test_table
| WHERE field1 IS NOT NULL AND
| tag;
|
No, I mean that the view behaves like a table with the same columns as
table, but that restricts to records on wich tag is set. To insert a
record to this "special" table it requires to have field1 set. In other
words: A record of table is a record of view if tag is set. If tag is
set, then field1 has also have to have a value. If tag is not set, it
may have a value for field1, but will not show up in the view. Of course
I could achive this be triggers, but I thought it could be possible to
do via constraints on the view.

Regards

Andreas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Debian - http://enigmail.mozdev.org

iD8DBQE/bF30PkvkZVZzNY0RAqh8AJ0ZwagGrOhyuma/7gARKl1l35/wOACfVj9d
xYvyd2Pet25drqcv4vBE5eg=
=jXUQ
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #3
Andreas Fromm <An***********@physik.uni-erlangen.de> writes:
No, I mean that the view behaves like a table with the same columns as
table, but that restricts to records on wich tag is set. To insert a
record to this "special" table it requires to have field1 set. In other
words: A record of table is a record of view if tag is set. If tag is
set, then field1 has also have to have a value. If tag is not set, it
may have a value for field1, but will not show up in the view. Of course
I could achive this be triggers, but I thought it could be possible to
do via constraints on the view.


Constraints on a view are meaningless --- it has no real rows to
constrain. Put the constraints on the underlying table.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Agoston Bejo | last post by:
Hi, I'm having trouble with implementing some constraints on the database level. An example: --Table A(AID, BID ref. B.BID, ATXT) --Table B(BID, CID ref. C.CID) --Table C(CID) upon insertion...
4
by: Dmitri | last post by:
I just looked at a coworker's stored procedure and this person is dropping 4 Foreign key constraints and then re-adding them after processing the required logic (updating rows in the 4 tables in...
2
by: DW | last post by:
Greetings: I have to do a one-off forceful change of some data in a database. I need to disable some FK constraints, make the data change, and then re-enable the constraints. My process will...
10
by: serge | last post by:
I am doing a little research on Google about this topic and I ran into this thread: ...
1
by: Bob | last post by:
Hi, Does anyone know why forgein key constraints are not enforced when updateing multiple tables using a combination of views and rules? This doesn't seem to be a major problem as I can...
2
by: Harold Howe | last post by:
Howdy all, I am getting a compiler error regarding a consrained conversion. It complains that it can't make the type conversion, even though the generic type argument inherits from the target of...
6
by: sarada7 | last post by:
How to check if DB Constraints are enabled in a database?
15
by: rod.weir | last post by:
Fellow database developers, I would like to draw on your experience with views. I have a database that includes many views. Sometimes, views contains other views, and those views in turn may...
0
by: Nate Eaton | last post by:
According to the original whitepaper on UDB range partitioning (http:// www-106.ibm.com/developerworks/db2/library/techarticle/0202zuzarte/ 0202zuzarte.pdf), you can use a range as a criteria,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.