Re: Difficulty modelling sales taxes

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Melvin Davidson <melvin6925(at)gmail(dot)com>
Cc: Frank Millman <frank(at)chagford(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Difficulty modelling sales taxes
Date: 2017-01-02 16:27:30
Message-ID: 0b615fa5-8dcf-6f02-f6ef-496e19967266@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/02/2017 08:02 AM, Melvin Davidson wrote:
>
>

>
> *First, there is no need to make row_id's when you already have
> a valid
> primary key.
>
>
> In a perfect world yes, but this is a world with ORM's as I found
> out the hard way:
>
> https://docs.djangoproject.com/en/1.10/ref/models/fields/#primary-key <https://docs.djangoproject.com/en/1.10/ref/models/fields/#primary-key>
>
> "The primary key field is read-only. If you change the value of the
> primary key on an existing object and then save it, a new object
> will be created alongside the old one."
>
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>
>
>
> *>https://docs.djangoproject.com/en/1.10/ref/models/fields/#primary-key
> <https://docs.djangoproject.com/en/1.10/ref/models/fields/#primary-key>
> *
> *You are quoting from a django document. Please don't muddle the waters.

Not sure I follow. You said:

"First, there is no need to make row_id's ..."

I was just pointing out that this is not a hard and fast rule and that
sometimes you are required to come up with a compromise solution.

> So you are saying this will not work?

Yes, if you want to bypass the ORM and want to run into FK problems.

> UPDATE mytable
> SET mykey = 'new_value'
> WHERE mykey = 'old_value';

Under Django you would now have one row with the new_value and another
with the old_value. Assuming mytable has child tables that reference
mykey, the child tables would be still referencing the old_value.

>
> DELETE FROM mytable
> WHERE mykey = 'old_value';

What happens now depends on how you have CASCADING set up. In any case
you would be doing more work to bring the child tables back into sync
with the parent table. For me the easiest the thing to do was bow to the
ORM convention and put in an integer PK.

> *
> *Happy New Year Adrian*
>
> --
> *Melvin Davidson*
> I reserve the right to fantasize. Whether or not you
> wish to share my fantasy is entirely up to you.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vincent Veyron 2017-01-02 16:31:19 Re: Difficulty modelling sales taxes
Previous Message Tom Lane 2017-01-02 16:21:29 Re: COPY: row is too big