Re: PreparedStatement and DB default values - Mailing list pgsql-jdbc

From Tomisław Kityński
Subject Re: PreparedStatement and DB default values
Date
Msg-id 007101c226b7$2db2abf0$e1e163d9@xpecet
Whole thread Raw
In response to PreparedStatement and DB default values  (Tomisław Kityński <cromax@amiga.pl>)
List pgsql-jdbc
----- Original Message -----
From: "Barry Lind" <barry@xythos.com>
To: "Tomisław Kityński" <cromax@amiga.pl>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Monday, July 08, 2002 6:40 PM
Subject: Re: [JDBC] PreparedStatement and DB default values


> Do you have any triggers or rules on this table that might be causing
> the problem?
>
  As stated in previous mail, I have defined two rules for the table
and few constraint triggers. The rules are:

CREATE RULE "on_delete_to_users" AS
ON DELETE TO "users"
DO
(
 UPDATE "news"
 SET "id_author" = -1
 WHERE "id_author" = OLD."id_user";

 UPDATE "comments"
 SET "id_author" = -1
 WHERE "id_author" = OLD."id_user"
);

CREATE RULE "on_insert_to_users" AS
ON INSERT TO "users"
DO
(
 INSERT INTO "given_permissions" VALUES (1, NEW."id_user");
 INSERT INTO "given_permissions" VALUES (2, NEW."id_user");
 INSERT INTO "given_permissions" VALUES (3, NEW."id_user");
);

In meantime I figured out, that dropping the "on_insert_to_users"
rule allowed me to insert default value into "users" table.

However, in PSQL documentation I have found this:

"The action [defined in rule] is done instead of the original query
if INSTEAD is specified; otherwise it is done after the original
query in the case of ON INSERT, or before the original query in the
case of ON UPDATE or ON DELETE".

So, in this particular case, in NEW tuple inside of rule
"on_insert_to_users",
there should be already--as stated in documentation--default value of
id_user taken from sequence. This is obviously not true. And in fact
this is related to PSQL itself and not to JDBC drivers.

Anyway thank you for your time and help. It seems like I have to post
my problem to different mailing group 8)





pgsql-jdbc by date:

Previous
From: "Simon Kitching"
Date:
Subject: Re: Managing database with PostgreSQL
Next
From: Dan Brown
Date:
Subject: JDBC 2.0 Datasource support?