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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:43:08+00:00 2026-05-25T16:43:08+00:00

I was asked to fix a problem with the website of a customer, and

  • 0

I was asked to fix a problem with the website of a customer, and I think this line is at least partly responsible for the error:

$SQL="select 'SC' ||substr(10000+max(to_number(secondid, '99G999D9S'))+1,2,4) from table";

I can’t quite tell what this line above is trying to accomplish, whether it’s just a bad piece of code that wasn’t written correctly or something important and well thought out. I know that substr is a PHP function, and yet, it’s in the double quotes, so it’s part of the query, and I also know that max and to_number are postgresql functions.
I have no idea what SC is, it isn’t a field in the table. If I run this query by itself:

SELECT 'SC' FROM table;

I get a ?column?(of unknown type), and the number of rows is one greater than the number of rows in the table (or the same if you include the empty row at the end of each table). Each row simply states holds SC.
What’s the point of the || operator? If I recall correctly, that is an OR operator, so how does the query decide what it wants to select?

Sorry for the trouble, thanks for your time.

  • 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-25T16:43:09+00:00Added an answer on May 25, 2026 at 4:43 pm

    The query is taking the value of field secondid, converts it to numerical, using 99G999D9S, then finds the max of these values across the table, add 10000 and 1 to it; converts the result to string, takes the substring 4-char long starting from the second character; finally appends it string ‘SC’ and returns to you. For a table where secondid column is defined and is formatted accordingly, you will get exactly 1 result back. If this column is not defined or is formatted differently, you’ll get an error.

    || operator is the concatenation in SQL.

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

Sidebar

Related Questions

I know that snapshot isolation would fix this problem, but I'm wondering if NOLOCK
Although this question have been asked and answered before, including on this website, I
I'm trying to fix the problem asked / answered here: Repairing Postgresql after upgrading
Hey, I've been trying to fix this problem for a long time, The problem
I think this has been asked a million times, but with different definitions of
I once was asked to increase thread priority to fix a problem. I refused,
I've asked this question before, here , however that solution didn't fix it when
This question has been asked a lot here, but i still can't fix my
I've been reading a lot about this since I've been asked to fix a
I am sure this problem is asked a lot but I can't seem to

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.