Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
How can I translate a script I wrote in SQL server to compute the odds ratios to Postgresql?

In SQL server, I wrote the following script to calculate the odds ratios based the probabilities of my test group divided by my control group. The script is as follows:

--Compute the odds ratios from the model  
select a.column1, a.uvs as testuvs. b.uvs as controluvs
       , [odds]=case when b.uvs>0 then a.puvs/b.puvs else Null end 
into unique_visitor_odds 
from control_probabilties b
    inner join test_probabilities a
    on a.column1=b.column2
 where a.uvs>24 and b.uvs>24 
 order by [odds] desc 

I am not sure how to write this in Postgresql.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The code is remarkably similar:

create table unique_visitor_odds as
    select tp.column1, tp.uvs as testuvs, cp.uvs as controluvs,
           tp.puvs / nullif(cp.puvs, 0) as odds
    from control_probabilties cp inner join
         test_probabilities tp
         on tp.column1 = cp.column2
    where cp.uvs > 24 and tp.uvs > 24 
    order by odds desc ;

I removed the case statement in the select. That is handled by the where. Postgres is smart enough to respect the where when reporting errors. And, you can prevent a divide by zero by using nullif().

Except fro the create table as and into clauses, the same code works in both databases.

Also, the order by is suspicious. I'm actually surprised the SQL Server allows it.

over 4 years ago · Santiago Trujillo Denunciar

0

Besides the potential type between your second and third column in the SELECT clause and the oddball alias syntax, everything should translate to postgres easily:

SELECT a.column1,
    a.uvs AS testuvs,
    b.uvs AS controluvs,
    CASE WHEN b.uvs > 0 THEN a.puvs / b.puvs ELSE NULL END AS odds
INTO unique_visitor_odds
FROM control_probabilties b
INNER JOIN test_probabilities a ON a.column1 = b.column2
WHERE a.uvs > 24 AND b.uvs > 24
ORDER BY odds DESC
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda