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 6708507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:46:05+00:00 2026-05-26T07:46:05+00:00

A while back, I asked about changing a MySQL query into Postgresql . And,

  • 0

A while back, I asked about changing a MySQL query into Postgresql. And, I think I got that down, but now, I have this other query which is similar, so I did the same sort of thing, but I am not sure if it’s working as intended.
The Original MySQL query:

create temporary table IF NOT EXISTS temptable(id int(11) primary key, shared int(1) default 0) 
ignore (SELECT 6 as id) UNION (SELECT user2role.userid AS userid FROM user2role 
INNER JOIN users ON users.id=user2role.userid 
INNER JOIN role ON role.roleid=user2role.roleid 
WHERE role.parentrole like 'H1::H2::H3::H4::H5::%') 
UNION (SELECT groupid FROM groups where groupid in (3,4,2));

My Postgresql(9.1) version:

Create TEMP TABLE IF NOT EXISTS temptable(id int primary key, shared int default 0);
Insert into temptable SELECT x.id FROM ( SELECT user2role.userid AS id FROM user2role 
INNER JOIN users ON users.id=user2role.userid 
INNER JOIN role ON role.roleid=user2role.roleid WHERE role.parentrole like 'H1::H2::H3::H4::%' 
UNION (SELECT groupid FROM groups where groupid in (2,3,4))) x 
LEFT JOIN temptable t USING (id) WHERE t.id IS NULL

Now, I am most worried about the ignore (SELECT 6 as id) UNION bit. I don’t quite understand the point of SELECT 6 as id.

Also, this is irrelevant to this query, but I have another similar query that uses replace instead of ignore. I understand that replace is a lot like insert, just that it replaces old values if they have the same key. I couldn’t think of a better way, so I just went ahead and used insert, but should I implement it in a different way instead?

Thanks for everything, guys.

  • 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-05-26T07:46:06+00:00Added an answer on May 26, 2026 at 7:46 am
    • IGNORE means that rows already present in the table will not be inserted. As you have just created the table, there cannot be any rows yet. Therefore, the option is irrelevant in this case.

    • MySQL REPLACE should be a

      DELETE .. USING insert_list .. WHERE ...;
      INSERT .. ;
      

    in one transaction. If an INSERT without DELETE succeeds, than the result is valid. There were no rows with conflicts, so the DELETE was not necessary in the first place. However, you risk that the operation is rolled back if any of the existing rows conflict with the INSERT. That does no harm other than gaps in sequences, which are never rolled back.

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

Sidebar

Related Questions

I asked this question a while back but now I'm looking to implement an
I noticed that a while back a question was asked about personal preferences in
So I asked a question a while back about securing downloads using C# (
A while back, I asked a question on here about how to run an
I asked a similar question here a while back but all the answers were
I previously asked a similar question on this topic a while back and got
I asked a question a while back about how to get the current variable
A while back I asked a question about TransactionScope escalating to MSDTC when I
Similar to what I asked in this question a while back about getting the
I was working with a new C++ developer a while back when he asked

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.