postgresql - How to get min/max of two integers in Postgres/SQL?

ID : 20256

viewed : 10

Tags : postgresqlpostgresql

Top 5 Answer for postgresql - How to get min/max of two integers in Postgres/SQL?

vote vote

99

Have a look at GREATEST and LEAST.

UPDATE my_table SET my_column = GREATEST(my_column - 10, 0); 
vote vote

83

You want the inline sql case:

set my_column = case when my_column - 10 > 0 then my_column - 10 else 0 end 

max() is an aggregate function and gets the maximum of a row of a result set.

Edit: oops, didn't know about greatest and least in postgres. Use that instead.

vote vote

76

vote vote

61

Don't post the data as an array. To bind to a list, the key/value pairs should be submitted with the same value for each key.

You should not need a form to do this. You just need a list of key/value pairs, which you can include in the call to $.post.

vote vote

54

In .NET4.5, MVC 5

Javascript:

object in JS: enter image description here

mechanism that does post.

    $('.button-green-large').click(function() {         $.ajax({             url: 'Quote',             type: "POST",             dataType: "json",             data: JSON.stringify(document.selectedProduct),             contentType: 'application/json; charset=utf-8',         });     }); 

C#

Objects:

public class WillsQuoteViewModel {     public string Product { get; set; }      public List<ClaimedFee> ClaimedFees { get; set; } }  public partial class ClaimedFee //Generated by EF6 {     public long Id { get; set; }     public long JourneyId { get; set; }     public string Title { get; set; }     public decimal Net { get; set; }     public decimal Vat { get; set; }     public string Type { get; set; }      public virtual Journey Journey { get; set; } } 

Controller:

[AcceptVerbs(HttpVerbs.Post)] public ActionResult Quote(WillsQuoteViewModel data) { .... } 

Object received:

enter image description here

Hope this saves you some time.

Top 3 video Explaining postgresql - How to get min/max of two integers in Postgres/SQL?

Related QUESTION?