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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:59:29+00:00 2026-06-13T17:59:29+00:00

I am using PostgreSQL and I would like to update a table which would

  • 0

I am using PostgreSQL and I would like to update a table which would include an auto number column id. I know it might something very simple but I have done something like this;

CREATE SEQUENCE  SEQ_ID
MINVALUE 1
START WITH 1
INCREMENT BY 1
CACHE 10

update trk2
set (id, track_id, track_point) =
           (select nextval('seq_id'), trk1.track_fid, trk1.wkb_geometry
              from track_points_1 as trk1
             where track_fid = 0)

The thing is that it is giving me the following error (code reformatted):

ERROR:  syntax error at or near "select"
LINE 3: set (id, track_id, track_point)=(select nextval('seq_id'), t...

Can anybody help please?

  • 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-13T17:59:30+00:00Added an answer on June 13, 2026 at 5:59 pm

    Your query is broken in several places. It could look something like this:

    UPDATE trk2
    SET   (id, track_id, track_point) = 
          (next_id, x.track_fid, x.wkb_geometry)
    FROM  (
       SELECT id
             ,nextval('seq_id') AS next_id
             ,track_fid
             ,wkb_geometry
       FROM   track_points_1
       WHERE  track_fid = 0
       ) x
    WHERE  trk2.id = x.id;  -- adapt to your case
    

    Or simpler (preferable syntax):

    UPDATE trk2
    SET   (id, track_id, track_point) = 
          (nextval('seq_id'), x.track_fid, x.wkb_geometry)
    FROM   track_points_1 x
    WHERE  x.track_fid = 0
    AND    trk2.id = x.id;   -- adapt to your case
    

    Major points:

    • An UPDATE without a WHERE clause only makes sense if you really need to change each and every row in the table. Else it is wrong or at least sub-optimal.

      When you retrieve values from another table, you get a CROSS JOIN between target and source if you don’t add a WHERE clause connecting target with source – meaning that every row of the target table will be updated with every row in the source table. This can take a very long time and lead to arbitrary results. The last UPDATE wins. In short: this is almost always complete nonsense and extremely expensive at that.

      In my example I link target and source by the id column. You have to replace that with whatever fits in your case.

    • You can assign multiple values in one SET clause in an UPDATE, but you can only return a single value from a correlated subselect expression. Therefore, it is strictly not possible to have a subselect in a SET clause with multiple values.

    • Your initial syntax error comes from a missing pair of parenthesis around your subselect. But adding that only reveals the error mentioned above.

    • Depending on what you are after, you would include nextval('seq_id') in the subquery or in the SET clause directly. This can lead to very different results, especially when you have rows in the subquery that are not used in the UPDATE.

      I placed it in the SET clause because I suspect, that’s what you want. The sequence of rows is still arbitrary. If you want more control over which numbers are assigned, you need to define what you want and then take a different route.

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

Sidebar

Related Questions

I would like to know the performance difference in updating a table using the
I'm using postgresql 8.3 and i would like to know the timezone of a
(I am using PostgreSQL) I have a table which stores transactions to an account.
I'm using postgresql 9.1.6 on CentOS. I would like to install the postgresql-contrib module
I am using PostgreSQL and would like to prevent certain required CHARACTER VARYING (VARCHAR)
I would like to create a web application using PostgreSQL as a database. I
I am using Play Framework 1.2.4 with PostgreSQL and JPA . I would like
I'm using Postgres and would like to make a big update query that would
I'm trying to learn SQL, using PostgreSQL 9.1.3. I would like to understand some
I'm using a framework (Jodd) which is adding the table alias to the column

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.