People, I have the following table [5m records] and I need to add a
column that uses a the listed UDF to count the number of days within
specific quarters by year.
CREATE TABLE HISTORY_MB (
ID INTEGER NOT NULL,
DAYS_RL INTEGER NOT NULL,
DAYS_RH INTEGER NOT NULL,
DAYS_RB INTEGER NOT NULL,
QTR SMALLINT NOT NULL,
YR SMALLINT NOT NULL,
CONSTRAINT HIST_PK_01 PRIMARY KEY(ID, QTR, YR))
NOT LOGGED INITIALLY
IN RESULTS INDEX IN INDEXES;
-- returns a count of the number of days within a qtr by year
CREATE FUNCTION GET_NO_TRANS_QTR( V_YEAR INTEGER,
V_QTR INTEGER)
RETURNS INTEGER
READS SQL DATA
LANGUAGE SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN
SELECT COUNT(ACT_DATE)
FROM CALENDAR
WHERE YEAR(ACT_DATE) = V_YEAR
AND QUARTER(ACT_DATE) = V_QTR ;
ALTER TABLE HISTORY_MB
ADD COLUMN NO_TRANS INTEGER GENERATED ALWAYS AS
(GET_NO_TRANS_QTR(YR,QTR));
I am getting the following error however:
SQL0548N A check constraint or generated column that is defined with
"GET_NO_TRANS_QTR" is invalid. SQLSTATE=42621
I've tried all manner of alternatives but cannot figure what I am doing
wrong. I've also tried turning off integrity, but still no good. Any
help would be greatly appreciated.
Many thanks,
Tim 1 6656
p175 wrote: People, I have the following table [5m records] and I need to add a column that uses a the listed UDF to count the number of days within specific quarters by year.
CREATE TABLE HISTORY_MB ( ID INTEGER NOT NULL, DAYS_RL INTEGER NOT NULL, DAYS_RH INTEGER NOT NULL, DAYS_RB INTEGER NOT NULL, QTR SMALLINT NOT NULL, YR SMALLINT NOT NULL, CONSTRAINT HIST_PK_01 PRIMARY KEY(ID, QTR, YR)) NOT LOGGED INITIALLY IN RESULTS INDEX IN INDEXES; -- returns a count of the number of days within a qtr by year CREATE FUNCTION GET_NO_TRANS_QTR( V_YEAR INTEGER, V_QTR INTEGER) RETURNS INTEGER READS SQL DATA LANGUAGE SQL NO EXTERNAL ACTION DETERMINISTIC RETURN SELECT COUNT(ACT_DATE) FROM CALENDAR WHERE YEAR(ACT_DATE) = V_YEAR AND QUARTER(ACT_DATE) = V_QTR ; ALTER TABLE HISTORY_MB ADD COLUMN NO_TRANS INTEGER GENERATED ALWAYS AS (GET_NO_TRANS_QTR(YR,QTR));
I am getting the following error however:
SQL0548N A check constraint or generated column that is defined with "GET_NO_TRANS_QTR" is invalid. SQLSTATE=42621
I've tried all manner of alternatives but cannot figure what I am doing wrong. I've also tried turning off integrity, but still no good. Any help would be greatly appreciated.
Many thanks,
Tim
db2 "? SQL0548"
<blah>
o the definition contains a user defined function with the
CONTAINS SQL or READS SQL DATA option
<blah>
Generated Columns are half trigger, half check constraint.
How can you have a check constraint which's correctness is based on
values in another table? (well one could semnatically, but it's one heck
of a maintenance job)
You could conceivably use an MQT or a view....
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dylan Nicholson |
last post by:
Seems that Oracle 9.2 (using MS ODBC driver) requires extra
parentheses when adding multiple columns to a table:
ALTER TABLE MyTable ADD (MyColumn1 VARCHAR(255), MyColumn2
VARCHAR(255))
vs
...
|
by: Dan Edwards |
last post by:
Hi about 2 months ago I had trouble with alter table on large tables
blocking all database activity and started a thread on this list called
"alter table blocks other tables!"
I tried to resolve...
|
by: Lannsjo |
last post by:
I need to change my primary key column type from smallint to int.
I have tried:
ALTER TABLE livegroup MODIFY id INT UNSIGNED NOT NULL AUTO_INCREMENT;
But get an error message certainly since my...
|
by: me |
last post by:
I would like to add an Identity to an existing column in a table using a
stored procedure then add records to the table and then remove the identity
after the records have been added or something...
|
by: pb648174 |
last post by:
I am trying to add a column to a temp table and then immeditaely query
against that new column. If I do this in Query Analyzer it works fine
as long as there is a go in between, but I can't use a...
|
by: Jeff Kish |
last post by:
Hi.
I have a database I need to supply something (I'm assuming a t-sql script..
maybe something else is better) to update customer tables with.
The operations include mostly changing varchar...
|
by: RamaKrishna Narla |
last post by:
In MS SQL Server, I have the following tables with some data in it.
create table table1 (
column1 varchar(32),
column2 int not null,
column10 varchar(255),
.....
primary key (column1,...
|
by: Serge Rielau |
last post by:
Hi all,
Following Ian's passionate postings on problems with ALTOBJ and the
alter table wizard in the control center I'll try to explain how to use
ALTOBJ with this thread. I'm not going to get...
|
by: vasilip |
last post by:
I'm testing out db2 for a project I'm starting that requires proper xml
support and I can't seem to get both xml and spatial data to work well
in the same table.
Once having created a table...
|
by: sparks |
last post by:
several months ago I was trying to set the field size of text fields
in a table and Lyle Fairfield was nice enought to post a way using
alter column.
it was surprising since it was ALTER COLUMN...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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...
|
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,...
| |