473,412 Members | 4,127 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,412 software developers and data experts.

COPY FROM fails to trigger rules

I'm using postgresql 7.4.2 and COPY FROM don't trigger INSERT rules.

Definitions:
| CREATE TABLE log.package_status (
| version integer NOT NULL,
| architecture integer NOT NULL,
| distribution integer NOT NULL,
| status_old integer,
| time timestamp NOT NULL,
| UNIQUE (version, architecture, distribution, time)
| );
|
| CREATE TABLE package.status (
| version integer NOT NULL,
| architecture integer NOT NULL,
| distribution integer NOT NULL,
| status integer,
| UNIQUE (version, architecture, distribution)
| );
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT version FOREIGN KEY (version) REFERENCES package.version
| ON DELETE CASCADE;
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT architecture FOREIGN KEY (architecture) REFERENCES def..architecture;
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT distribution FOREIGN KEY (distribution) REFERENCES def..distribution;
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT status FOREIGN KEY (status) REFERENCES def.package_status;
|
| CREATE INDEX architecture_distribution_index ON package.status (architecture, distribution);
|
| CREATE RULE status_insert AS ON INSERT TO package.status
| DO INSERT INTO log.package_status (version, architecture, distribution, time)
| VALUES (NEW.version, NEW.architecture, NEW.distribution, current_timestamp);
|
| CREATE RULE status_update AS ON UPDATE TO package.status
| WHERE NEW.status <> OLD.status
| DO INSERT INTO log.package_status (version, architecture, distribution, status_old, time)
| VALUES (NEW.version, NEW.architecture, NEW.distribution, OLD.status, current_timestamp);

The data is inserted via the following call into an mostly empty database:
| COPY package.status (version, architecture, distribution, status) FROM STDIN

It was created from a template which contains a few functions and
operators.

After all data is commited I get the following, it is reproducable:
| multibuild=> SELECT count(*) from package.status;
| count
| -------
| 15130
| (1 row)
|
| multibuild=> SELECT count(*) from log.package_status;
| count
| -------
| 0
| (1 row)

Tests with INSERT always triggers the rule.

Bastian

--
.... The prejudices people feel about each other disappear when they get
to know each other.
-- Kirk, "Elaan of Troyius", stardate 4372.5

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iEYEARECAAYFAkC57MYACgkQnw66O/MvCNFoowCgjaowH5YWuNlNt/vc5bUdOHaO
VVkAoICGkZgbJIjdrwPwbxyYXnILE0Zd
=EFTg
-----END PGP SIGNATURE-----

Nov 23 '05 #1
1 1912
On 5/30/2004 10:16 AM, Bastian Blank wrote:
I'm using postgresql 7.4.2 and COPY FROM don't trigger INSERT rules.
Right, and it never did. COPY does not pass the query rewrite engine.
Jan

Definitions:
| CREATE TABLE log.package_status (
| version integer NOT NULL,
| architecture integer NOT NULL,
| distribution integer NOT NULL,
| status_old integer,
| time timestamp NOT NULL,
| UNIQUE (version, architecture, distribution, time)
| );
|
| CREATE TABLE package.status (
| version integer NOT NULL,
| architecture integer NOT NULL,
| distribution integer NOT NULL,
| status integer,
| UNIQUE (version, architecture, distribution)
| );
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT version FOREIGN KEY (version) REFERENCES package.version
| ON DELETE CASCADE;
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT architecture FOREIGN KEY (architecture) REFERENCES def.architecture;
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT distribution FOREIGN KEY (distribution) REFERENCES def.distribution;
|
| ALTER TABLE ONLY package.status
| ADD CONSTRAINT status FOREIGN KEY (status) REFERENCES def.package_status;
|
| CREATE INDEX architecture_distribution_index ON package.status (architecture, distribution);
|
| CREATE RULE status_insert AS ON INSERT TO package.status
| DO INSERT INTO log.package_status (version, architecture, distribution, time)
| VALUES (NEW.version, NEW.architecture, NEW.distribution, current_timestamp);
|
| CREATE RULE status_update AS ON UPDATE TO package.status
| WHERE NEW.status <> OLD.status
| DO INSERT INTO log.package_status (version, architecture, distribution, status_old, time)
| VALUES (NEW.version, NEW.architecture, NEW.distribution, OLD.status, current_timestamp);

The data is inserted via the following call into an mostly empty database:
| COPY package.status (version, architecture, distribution, status) FROM STDIN

It was created from a template which contains a few functions and
operators.

After all data is commited I get the following, it is reproducable:
| multibuild=> SELECT count(*) from package.status;
| count
| -------
| 15130
| (1 row)
|
| multibuild=> SELECT count(*) from log.package_status;
| count
| -------
| 0
| (1 row)

Tests with INSERT always triggers the rule.

Bastian

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = Ja******@Yahoo.com #
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2

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

Similar topics

6
by: Dave C. | last post by:
Hello, I have created the following trigger: CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATE AS DECLARE @foobar varchar(100) SELECT @foobar= foobar FROM inserted IF (...
3
by: Terri | last post by:
I'm using xp_cmdshell to output a text file from a trigger like this CREATE TRIGGER ON tblApplications FOR INSERT AS DECLARE @FirstName varchar(75) DECLARE @LastName varchar(75) Declare...
8
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is...
42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
7
by: rkrueger | last post by:
Given the following 3 Tables: CREATE TABLE ( NOT NULL , NOT NULL CONSTRAINT DEFAULT (getdate()), NULL , CONSTRAINT PRIMARY KEY CLUSTERED (
3
by: Ericson Smith | last post by:
Hi, Is there any way to prevent a trigger from firing during a COPY operation? We have a case where we dump the records from a table, truncate it, and copy the records back in. However, there...
5
by: Dave Sisk | last post by:
Hey folks: I'm trying to do this: CREATE TRIGGER datawhse.emp_ti AFTER INSERT ON emp REFERENCING NEW AS n FOR EACH ROW MODE DB2ROW BEGIN DECLARE v_rrn DECIMAL(15,0);
2
by: Dima Gofman | last post by:
I have a trigger on UPDATE on a table. I'm running some maintenance UPDATE and DELETE queries which I want the trigger to ignore but at the same time I want other UPDATE queries that other users...
0
by: gshawn3 | last post by:
Hi, I am having a hard time creating a Trigger to update an Oracle database. I am using a SQL Server 2005 Express database on a Win XP Pro SP2 desktop, linked to an Oracle 10g database on a...
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?
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
marktang
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,...
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
Oralloy
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,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.