From: Hiroshi Inoue <inoue@tpf.co.jp>
To: greg.campbell@us.michelin.com
Cc: pgsql-odbc@postgresql.org
Subject: Re: '= NULL' is not the same as 'IS NULL'
Date: Sat, 09 Sep 2006 01:12:52 +0900
Message-ID: <45019684.9010902@tpf.co.jp> (raw)
In-Reply-To: <OF9E7EB010.A1034068-ON852571E3.004E979D-852571E3.004EA07D@michelin.com>
References: <OF9E7EB010.A1034068-ON852571E3.004E979D-852571E3.004EA07D@michelin.com>
Hi greg,
greg.campbell@us.michelin.com wrote:
> Thanks Hiroshi for the insight and the history lesson.
>
> In light of this I decided to further my education by doing some testing
> against a simple table.
>
> CREATE TABLE test
> (
> emp_id serial NOT NULL,
> last_name varchar(20) NOT NULL,
> first_name varchar(20) NOT NULL,
> "level" int4,
> CONSTRAINT emp_id_pk PRIMARY KEY (emp_id)
> )
>
> In my table I have a field named "level" which is allowed to be NULL.
>
> I set the DSN to do row versioning, and ran the pgODBC CommLog at the same
> time as the ODBC Trace (because a good masochist loves to observe the
> statement handles).
> In general I did not find the MSAcess to do WHERE match querying before an
> update, but it did do one after an update to apparently count the number of
> rows, to see if what it just updated took hold.
>
I can see insert examples but can't see update ones here.
Insert operations are pretty different from update ones.
We have little to do before insert operations.
> There is a general pattern of
> 1.DML Executable (INSERT, UPDATE)
> 2. Select on primary_key = NULL (should fetch 0 rows)
> 3. Commit
> 4. Select on primary_key = NULL (should fetch 0 rows)
> 5. Select with the WHERE (exact match each non NULL field) to count the
> exact match, should be 1 ? or more?
> 6. Select using the primary key, (used to refresh the screen I think.)
>
I understand what MSACCESS means a little but not wholly.
> CommLog===============================================
> conn=147538008, query='INSERT INTO "public"."test"
> ("last_name","first_name") VALUES ('Rubble','Barney')'
>
The serious problem here is that the primary key was not given in the
above INSERT statement.
Firstly MSAccess guesses the primary key might have been NULL because
ommitted values
are generally NULL (MSAccess doesn't know inside PostgreSQL at all) and
issues the following
command.
> conn=147538008, query='SELECT
> "emp_id","last_name","first_name","level","xmin" FROM "public"."test"
> WHERE "emp_id" IS NULL'
> [ fetched 0 rows ]
> conn=147538008, query='COMMIT'
>
I don't know why MSAccess tries the same operation twice.
> conn=147538008, query='SELECT
> "emp_id","last_name","first_name","level","xmin" FROM "public"."test"
> WHERE "emp_id" IS NULL'
> [ fetched 0 rows ]
>
Here MSAccess gives up the direct primary key approach and searches key
of the
inserted record using known item values expecting that the matching
records are a few.
> conn=147538008, query='SELECT "public"."test"."emp_id" FROM "public"."test"
> WHERE "last_name" = 'Rubble' AND "first_name" = 'Barney''
> [ fetched 1 rows ]
>
Fortunately just 1 record was returned in this example.
What MSAccess has really wanted to know was the whole content of the
inserted record.
So it issues the following command finally.
> conn=147538008, query='SELECT
> "emp_id","last_name","first_name","level","xmin" FROM "public"."test"
> WHERE "emp_id" = 3'
> [ fetched 1 rows ]
regards,
Hirshi Inoue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: inoue@tpf.co.jp, greg.campbell@us.michelin.com
Subject: Re: '= NULL' is not the same as 'IS NULL'
In-Reply-To: <45019684.9010902@tpf.co.jp>
References: <OF9E7EB010.A1034068-ON852571E3.004E979D-852571E3.004EA07D@michelin.com> <45019684.9010902@tpf.co.jp>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox