En cours

relatively simple add/update postgreSQL query

have a query that inserts data into a table. But it is creating a new record every time. Is there a way I can check if the row is there first, then if it is, UPDATE, and if it isn't INSERT?

$user = 'username';

$timestamp = date('Y-m-d G:i:s.u');

$check_time = "start"; //can also be stop

$check_type = "start_user"; //can also be stop_user

$insert_query = "INSERT INTO production_order_process_log (production_order_id, production_order_process_id, $check_time, $check_type) VALUES ('$production_order_id', '$production_order_process_id', '$timestamp', '$user')";

The idea is that the table will record check-in and check-out values ([url removed, login to view] and [url removed, login to view]). So before a record with a check-out time stamp is made, the query should check to see if the $production_order_process_id already exists. if it does exist, then the timestamp can go into "stop" and the $check_type can be stop_user. Otherwise, they should stay "start" and "start_user".

I am basically trying to avoid this result.


| id | production_order_id |   production_order_process_id  |        start       |        stop       | start_user  |  stop_user  |


| 8  | 2343                |   1000                         |  12 july 03:23:23  | NULL              | tlh         |  NULL       |


| 9  | 2343                |   1000                         | NULL               | 12 july 03:45:00  | NULL        |  tlh        |


Additionally, if there is a production_order_process_id higher than the one which is currently getting the check-in or check-out, a new record should be created, rather than completing the old one. 

Additionally, if there is a row with the the production_order_id the same as the one the query is being performed on that does not have a check-out time, the $timestamp variable (minus one second) should be applied to it. Obviously, since this check will be performed every time, this can only happen once per query.?

Compétences : PHP, Architecture Logicielle, SQL

en voir plus : postgresql check check, update old, time stamp, simple query, postgresql c++, d g, insert variable, simple check date, add record, update insert sql, php sql update, simple add, check user already created php, postgresql sql, Postgresql php, postgresql table, record check, sql update, add 1000, data insert sql, sql exists insert update, sql table update data, simple sql update, relatively simple, completing simple

Concernant l'employeur :
( 12 commentaires ) chicago, United States

Nº du projet : #2346586

Décerné à:


Hi. I am familiar to PostgreSQL and PHP. I can easily fix your app. I just need less than a hour. Everything what I need is the access to your server or the file that you need to update. Regards.

%selectedBids___i_sum_sub_4% %project_currencyDetails_sign_sub_5% USD en 1 jour
(9 Commentaires)

6 freelance font une offre moyenne de $89 pour ce travail


Hi, I'm interested in working on this problem. One solution I can think of is writing Stored Proc where we can put all logic. But we can discuss and solve it. regards.

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 5 jours
(17 Commentaires)

Hello. I can help you. Anton.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(58 Commentaires)

I can do this right away for you. Quick and simple.

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 2 jours
(10 Commentaires)

hi... we are 5+ years exp in webdevelopment....

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(0 Commentaires)

Hi, I am an independent developer looking to take on some more work. I have 7+ years experience in PHP5 (OOP & Design pattern) with Zend framework. I can create custom web sites to fit your needs. I always prov Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 4 jours
(0 Commentaires)