473,387 Members | 1,476 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,387 software developers and data experts.

Using SUBSELECT in CHECK expressions

Is postgres going to support in a future release the use of SUBSELECT in a CHECK expression ??

Thx
Nov 12 '05 #1
7 3730
"Najib Abi Fadel" <na*******@usj.edu.lb> writes:
Is postgres going to support in a future release the use of SUBSELECT in a =
CHECK expression ??


Not very likely. To my mind, such a constraint would imply rechecking
whenever the table(s) read by the sub-SELECT change, not only when a
row of the constrained table changes. I don't know any reasonably
efficient implementation of that behavior. We might figure out how to
do it eventually, but don't hold your breath.

If you are satisfied with only a one-directional constraint (apply the
check just when the constrained table is modified), you can have it today.
Just put the SELECT into a function that's called by the CHECK
expression.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #2
On Tue, 4 Nov 2003, Najib Abi Fadel wrote:
Is postgres going to support in a future release the use of SUBSELECT in
a CHECK expression ??


Possibly, but AFAIK it's not on anyone's hit list in the short term, so
you're probably looking at multiple years unless you can do it or find
someone to do it.
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #3
On Wednesday, November 5, 2003, at 06:26 AM, Tom Lane wrote:
If you are satisfied with only a one-directional constraint (apply the
check just when the constrained table is modified), you can have it
today.
Just put the SELECT into a function that's called by the CHECK
expression.


Tom, you've just provided the solution to something I've been thinking
about a lot. I really have to start thinking in terms of functions. Are
there any restrictions on the function used in the CHECK, i.e., it must
be STRICT or IMMUTABLE? I took a quick look at the developer docs
(thinking they'd be for 7.4RC1. I was happily suprised to see they're
already labeled 7.5 dev!)

Michael
grzm myrealbox com
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #4
Michael Glaesemann <gr**@myrealbox.com> writes:
On Wednesday, November 5, 2003, at 06:26 AM, Tom Lane wrote:
Just put the SELECT into a function that's called by the CHECK
expression.
Tom, you've just provided the solution to something I've been thinking
about a lot. I really have to start thinking in terms of functions. Are
there any restrictions on the function used in the CHECK, i.e., it must
be STRICT or IMMUTABLE?


IIRC we check that it is labeled IMMUTABLE. Whether it really is or
not, we cannot check (and if it uses a SELECT on tables that could
change, then of course it isn't; so you are going to need to tell a
little white lie here).

Because of that, you need to be careful that you pass at least one
nonconstant argument to the function within the CHECK expression, else
you risk having the call constant-folded too early. Normally you'd
probably pass values from the checked row into the function, so this
doesn't seem like it should be a problem, but I could see someone
getting bit by it someday ...

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 12 '05 #5

On Thursday, November 6, 2003, at 02:38 AM, Tom Lane wrote:
Michael Glaesemann <gr**@myrealbox.com> writes:
On Wednesday, November 5, 2003, at 06:26 AM, Tom Lane wrote:
Just put the SELECT into a function that's called by the CHECK
expression.

Tom, you've just provided the solution to something I've been thinking
about a lot. I really have to start thinking in terms of functions.
Are
there any restrictions on the function used in the CHECK, i.e., it
must
be STRICT or IMMUTABLE?


IIRC we check that it is labeled IMMUTABLE. Whether it really is or
not, we cannot check (and if it uses a SELECT on tables that could
change, then of course it isn't; so you are going to need to tell a
little white lie here).

Because of that, you need to be careful that you pass at least one
nonconstant argument to the function within the CHECK expression, else
you risk having the call constant-folded too early. Normally you'd
probably pass values from the checked row into the function, so this
doesn't seem like it should be a problem, but I could see someone
getting bit by it someday ...


Thanks for the clarification. Is this in the documentation somewhere?
I'm not quite used to the new documentation ordering yet.

Michael
grzm myrealbox com
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #6
Michael Glaesemann <gr**@myrealbox.com> writes:
On Thursday, November 6, 2003, at 02:38 AM, Tom Lane wrote:
IIRC we check that it is labeled IMMUTABLE.
Thanks for the clarification. Is this in the documentation somewhere?


[digs...] No, because my recollection is wrong: there's no such check.

regression=# create function foo() returns bool as 'select true' language sql;
CREATE FUNCTION
regression=# create table foo (f1 int check (foo()));
CREATE TABLE

Possibly there should be such a restriction, but there isn't today...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #7

On Thursday, November 6, 2003, at 03:12 AM, Tom Lane wrote:
Michael Glaesemann <gr**@myrealbox.com> writes:
On Thursday, November 6, 2003, at 02:38 AM, Tom Lane wrote:
IIRC we check that it is labeled IMMUTABLE.

Thanks for the clarification. Is this in the documentation somewhere?


[digs...] No, because my recollection is wrong: there's no such check.


Thanks for, erm, checking! (Okay, I'm off to bed now.)

Michael
grzm myrealbox com
---------------------------(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 12 '05 #8

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

Similar topics

3
by: Guy Robinson | last post by:
I have the code below which parses an expression string and creates tokens. Can anyone suggest the best of error checking for things like: Valid variable only obj.attribute -whitespace allowed...
6
by: Greg Stark | last post by:
So I have a query in which some of the select values are subqueries. The subqueries are aggregates so I don't want to turn this into a join, it would become too complex and postgres would have...
3
by: Neil Zanella | last post by:
Hello, I would like to ask the about the following... PostgreSQL allows tables resulting from subselects to be renamed with an optional AS keyword whereas Oracle 9 will report an error...
2
by: Susanne Bandi | last post by:
Hello I've experienced that DB2 unfortunately does not eliminate subselects of a UnionAll-View if the predicate's content is not hardcoded but derived from a base-table with a noncorrelated...
5
by: Todd | last post by:
Data related to the query I'm working on is structured such that TableA and TableB are 1-many(optional). If an item on TableA has children on TableB, I need to use the Max(tstamp) from Table B in...
4
by: James | last post by:
I have a performance problem with the following query and variations on the subselect. The EXISTS version of the first example will complete in ~10 minutes. The NOT logic in both the examples...
4
by: dtwalter | last post by:
Is it possible to ORDER BY a SubSelect? I don't see why it wouldn't be, but I'm having some trouble. Hopefully it's just a simple error in syntax and somebody can tell me. Here's what I'm trying...
1
by: Marco Lazzeri | last post by:
I'd like to reference values returned by a subselect in the same SELECT query. Example: SELECT id, ( SELECT COUNT(*) FROM second ) AS value_to_reference, ( value_to_reference + 1 ) AS...
3
by: Jim C. Nasby | last post by:
I'm sure this has been answered before, but the search seems to be down again. How can I convert the results of a subselect into an array? IE: CREATE TABLE a(a int, b int, c int); INSERT INTO...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.