• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

256
Views
Shorter way to INSERT multiple variables into Postgres/SQL?

Picking up SQL and Postgres, is there a shorter way to write the INSERT SQL query than the code below?

Not a problem writing it this way but it's very long and requires lots of scrolling. I could write it as a paragraph with no linebreak after the commas but then it's hard to keep track of which variable/column/value goes with what in VSCODE.

Maybe there's a way to shorten the values variables such as writing something like $1-$39?

 const addItemSql = `
            INSERT INTO users (
                address,
                city,
                state,
                postal,
                description,
                bedrooms,
                bathrooms,
                sqft,
                lotSize,
                .....(20 more items) 
            ) VALUES (
                $1,
                $2,
                $3,
                $4,
                $5,
                $6,
                $7,
                $8,
                $9,
                $10,
                $11,
                $12,
                $13,
                $14,
                $15,
                $16,
                $17,
                $18,
                $19,
                $20,
                $21,
                $22,
                $23,
                $24,
                $25,
                $26,
                $27,
                $28,
                $29,
                $30,
                $31,
                $32,
                $33,
                $34,
                $35,
                $36,
                $37,
                $38,
                $39,
            ) RETURNING *`
    const { rows: addedItem } = await pool.query(addItemSql, [
        address,
            city,
            state,
            postal,
            description,
            bedrooms,
            bathrooms,
            sqft,
            lotSize,
            .....(20 more items) 
    ])
about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error