Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
Translate query from MSSQL to PostgreSQL

This query update one column if UserName has only numbers.

UPDATE [dbo].[MyTable]
SET [MyColumn] = CAST(CASE 
            WHEN UserName LIKE '%[^0-9]%'
                THEN 0
            ELSE 1
            END AS BIT)

I need to retranslate it to postgreSql. It must be something like this

UPDATE "MySheme"."MyTable"
SET "MyColumn" = CAST(CASE 
            WHEN "UserName" LIKE '%[^0-9]%'
                THEN 0
            ELSE 1
            END AS BIT)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Consider:

update mytable
set mycolumn = (username !~ '\d')::int::bit 

This produces a bit value of 1 if username does not contain any digit, else 0.

Note that Postgres supports the boolean datatype, that would probably make more sense here. This would also simply the query:

update mytable
set mycolumn = (username !~ '\d')

Note that I did not quote the identifiers. Quoted identifiers usually add no value, and make queries unnecessarily lengthy - I would recommend avoiding them in your set up.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!