Database Development

Is it bad practice to calculate within the insert query?

I am trying to do a web application for time sheets.

I have three options to calculate the value of hours (AFAIK):

  1. In the form
  2. In the backend
  3. In the query

Is it smart or bad practice to do this calculation in the SQL query?

with list as (select code_id,code_ppu from code)

insert into hr values
(select code_ppu from list where code_id='PM'),
(select 1.25 * code_ppu from list where code_id='PM')),
(select code_ppu from list where code_id='COPY'),
(select 2.25 * code_ppu from list where code_id='COPY'));

db fiddle

Leave a Reply

Your email address will not be published. Required fields are marked *