Unexpected behaviour of 'DEFERRABLE INITIALLY DEFERRED'

From: Jong-won Choi <jongwon(dot)choi(at)internode(dot)on(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Unexpected behaviour of 'DEFERRABLE INITIALLY DEFERRED'
Date: 2015-11-25 12:32:48
Message-ID: 5655AA70.5080709@internode.on.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

This is from my local PostgreSQL log:

====
LOG: statement: begin;
LOG: statement: INSERT INTO site_owner (email, name, pwhash, data)
VALUES ('xyz', 'xyz', crypt('xyz', gen_salt('bf', 8)), '{}'::JSONB)
RETURNING id;
LOG: statement: INSERT INTO site (owner, name, timezone, data) VALUES
('150c2fff-1029-47a5-aaa8-3e974e8442c6', 'sitex', 'Australia/NSW',
'{}'::JSONB) RETURNING id;
LOG: statement: commit;

----

LOG: statement: BEGIN
LOG: execute <unnamed>: INSERT INTO site_owner (email, name, pwhash,
data) VALUES ($1, $2, crypt($3, gen_salt('bf', 8)), $4::JSONB) RETURNING id
DETAIL: parameters: $1 = 'test(at)email6', $2 = 'Name', $3 = 'password',
$4 = '{}'
LOG: execute <unnamed>: INSERT INTO site (owner, name, timezone, data)
VALUES ($1, $2, $3, $4::JSONB) RETURNING id
DETAIL: parameters: $1 = '3a83db7f-c82e-4b7a-a5c7-c0b43f415b0e', $2 =
'Test', $3 = 'Australia/NSW', $4 = '{}'
ERROR: insert or update on table "site" violates foreign key constraint
"site_owner_fkey"
DETAIL: Key (owner)=(3a83db7f-c82e-4b7a-a5c7-c0b43f415b0e) is not
present in table "site_owner".
LOG: statement: ROLLBACK
====

The first 'successful' part is a result of SQL statements from psql, and
the second 'unsuccessful' part is a result of client library function
calls from my application.

It seems to me they both have the same structure, except the first part
is consist of 'statements' and the second part is consist of
'execute'(prepare statements, I guess).

Any hints which can make the second part successful?

Thanks

- Jong-won

Responses

Browse pgsql-general by date

  From Date Subject
Next Message FarjadFarid(ChkNet) 2015-11-25 12:45:17 Re: full_page_writes on SSD?
Previous Message NTPT 2015-11-25 12:10:05 Re: full_page_writes on SSD?