Re: Semi-unable to add new records to table--primary key needed?

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Semi-unable to add new records to table--primary key needed?
Дата
Msg-id bccb5c7b-5a2c-f653-6e0c-f58290d88763@aklaver.com
обсуждение исходный текст
Ответ на Re: Semi-unable to add new records to table--primary key needed?  ("Boylan, Ross" <Ross.Boylan@ucsf.edu>)
Ответы Re: Semi-unable to add new records to table--primary key needed?  ("Boylan, Ross" <Ross.Boylan@ucsf.edu>)
Список pgsql-general
On 12/22/19 11:59 AM, Boylan, Ross wrote:
>> From: Adrian Klaver <adrian.klaver@aklaver.com>
>   > Sent: Sunday, December 22, 2019 10:35 AM
> .....
>> Alright this is the part where I got confused. I think what is going on is:
> 
>> 1) The immediate change is going to be to Access 2016 on Windows 10 64
> keeping the data in Access files(.accdb)
> 
>> 2) The long term plan is to move the data from the Access files to a
> stand alone SQL server, presumably Postgres. You are looking for
> assistance in converting Access tables and relationships to Postgres.
> 
>> 3) At some point the GUI will point to the data in the server instead of
> in the Access files.
> 
>> Is any of the above correct?
> 
> Basically, yes.
> 1) The current file is in the older Access .mdb format, and will stay that way for the immediate conversion to Win
10/Access2016.
 
> 2) I'd like to go to Postgres medium term.  I have converted the Access data to Postgres via an Access/VBA program
thatwrites out SQL files.  It clearly needs some work.
 

The long term solution is?

More answers inline below.

> I think I may have everything I need to tweak it.
> 3) Basically yes, though in detail the GUI and the code behind it directly use "linked tables"  that are local to the
frontend.  These linked tables are the Access equivalent of symlinks to a particular table on a particular database.
Theywill use the PG ODBC driver to do the talking.  The app uses those linked tables now, but the link simply points to
thebackend file on the disk.
 

So at some point you will switch the link from being Access native to a 
ODBC DSN pointing at a Postgres database, correct?

> 
> One other issue came up in testing: searches against the Access backend are case insensitive, while searches against
thePG backend are case-sensitive.  It would be nice to make them case-insensitive, and I've been reading about PG
collationoptions to do so.
 
> 
> Case-sensitivity is completely distinct from all the other issues I've discussed.  The sense was also that the
problem/differencewas not a show-stopper.  Current behavior is that if you search for id abc123 it will retrieve an id
storedas ABC123.  With the PG backend, searching on  abc123 retrieves nothing.
 

How about:


test=# select 'abc123' ilike 'ABC123';
  ?column?
----------
  t
(1 row)

> 
>> More below.
> 
>>>> 3) Have you looked at the Relations tab in Access to see what if any relationships are there?
> ....
>>
>>> Yes, but the export program doesn't :)  The relations tab documents many, but not all, of the relations in the
database. The relations are also a little tricky because sometimes the lack of a relation should not be considered
disqualifyingfor a specimen.  Simple example: freezer type is an id to be looked up in a small table of freezer type
idsand their names.  If the freezer type is missing or nonsense, we may still want the sample.  That can be expressed
asa left join; the "Access SQL is not SQL" problems centered on left joins.
 
> 
>> Postgres is going to be stricter about this. Access has the concept of
> suggested relationships that are not enforced:
> 
>>
https://urldefense.proofpoint.com/v2/url?u=https-3A__support.office.com_en-2Dus_article_Guide-2Dto-2Dtable-2Drelationships-2D30446197-2D4fbe-2D457b-2Db992-2D2f6fb812b58f&d=DwIDaQ&c=iORugZls2LlYyCAZRB3XLg&r=nh70E5-mX2XsDe5lrDDMt_ZRqqGMcdTmTrRLvNmttYA&m=qa1d513KOtyWtV0u2K81rduJ0TiRaucF3gbnjVTESkc&s=F10pVnItttte6dDN-4R4t13xDrJr8zAoIp63mrYNMh0&e=
> 
> Thanks for the pointer.  I'm not sure if we're using any of those suggested relationships, but we're definitely using
relationshipsthat one infers only by looking at the SQL code.  In other words, queries link tables by fields that are
notmentioned on the relationships tab.
 
> 
> ......
> 
>> Postgres Foreign Key relationships either exist or they don't. Now you
> can employee 'cheats' with you own triggers, but that is another subject.
> 
>> As to your freezer example:
> 
>> create table freezer_info(freezer_id int PRIMARY KEY);
>> create table sample_tbl(sample_id serial PRIMARY KEY, freezer_fk int
>> REFERENCES freezer_info ON UPDATE CASCADE);
> 
> The direct translation of our current app would be to omit the foreign key relation in the table definition, but to
havequeries that include a left join from sample_tbl to freezer_info.
 
> 
> That raises one other question: what is the relation between the relations expressed on the server via FOREIGN KEY
declarationsand relations known to Access?  At first blush, they are completely different.  In Access a relation is an
objectthat lives on the front-end, while the server relations obviously live on the server.  I don't know if Access,
perhapsvia the ODBC spec, does anything to guarantee their consistency.  Clearly since Access relations can have
"suggestedrelations" which have no backend equivalent, the 2 sets of relations cannot in general be mirror images.
 

Trying to parse the above out:

1) When you say relations you mean Foreign Key or equivalent, correct? 
Just confirming as relation is often used to mean table.

2) As I remember it an 'enforced relationship' in Access is actually a 
FK, whereas one that is not is just stored as metadata somewhere.

3) Are you are asking whether it possible for a table in an Access table 
can have a direct relationship with a table stored in Postgres and 
connected via ODBC? If so my answer is that I am not sure. I believe you 
can use the Relations tab to set up a faux relationship, but that will 
only be honored in the context of Access and only if you want it to.

4) You can set up an actual FK on the server between server tables, with 
the data clean up caveats you mention below.

5) At this point it seems your data is going to live in two worlds and 
in the end it will fall on you to maintain the integrity between the worlds.

> 
> Identifying and enforcing all foreign key relations, is something I'm planning to defer til after the migration to
PG. There is a noticeable amount of funky stuff in the data, which could use some housekeeping regardless of platform.
Thecleanup is not likely to be simple.
 
> 
> One of the long-run benefits of using a database server is that it should limit the possibilities for funkiness by
enforcingreferential integrity and properly cleaning up after incomplete operations, instead of leaving pieces of them
inthe database.  But we can't enforce referential integrity until our  data exhibit it! And the transactional integrity
probablydepends more on proper coding on the front-end app than the choice of backend; file-based Access backends do
supporttransactions.
 
> 
> Ross
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com



В списке pgsql-general по дате отправления:

Предыдущее
От: "Boylan, Ross"
Дата:
Сообщение: Re: Semi-unable to add new records to table--primary key needed?
Следующее
От: Andrei Pozolotin
Дата:
Сообщение: Question: what is proper way to define python function asevent_trigger?