Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:39:43+00:00 2026-06-08T01:39:43+00:00

Working on some postgreSQL queries. As I said in a previous question..my knowledge of

  • 0

Working on some postgreSQL queries. As I said in a previous question..my knowledge of SQL logic is quite limited..

I have this query that inserts a row.

$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')
";

Unfortunately, that is adding a new row every time. I would like to add conditional SQL so that

if the production_order_process_id doesn’t exist, do the INSERT as it’s written in the query above. That is, add the new row with all the new information

but if the production_order_process_id does exist and the check_type is stop_user then UPDATE the row to fill the column stop with the $timestamp and fill the column stop_user with $user.

I understand this is complicated.. Or, at least for me it is ^^ Thanks much for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:39:44+00:00Added an answer on June 8, 2026 at 1:39 am

    This is usually called MERGE or upsert. PostgreSQL doesn’t have explicit support for this operation.

    The best article I’ve seen on the topic of MERGE in PostgreSQL is this one by depesz .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m working on some sql queries to get some data out of a table;
I'm working on a PHP web application with PostgreSQL. All of the SQL queries
Whilst working on some generally horrible Javascript code this morning, I came across the
I have some working code with a crutch to add BOM marker to a
I'm working with some code. There are several queries whose effect is, if the
I've been migrating some of my MySQL queries to PostgreSQL to use Heroku. Most
I have a Postgresql dump file which i'm trying to restore. I get this
I have been working to upgrade a Postgresql database from 8.4 to 9.1. I
I am doing some research on migrating away from Microsoft sql server to postgresql
Some time ago i was working on a database made in Postgresql, i learned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.