Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Nick Sieger
Reporter: gmurphy44
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

Negative integer default values are ignored by the activerecord postgres adapter

Created: 08/Feb/11 07:52 PM   Updated: 21/Jun/11 05:26 PM   Resolved: 21/Jun/11 05:26 PM
Component/s: PostgreSQL
Affects Version/s: 1.1.0
Fix Version/s: 1.1.2

Time Tracking:
Original Estimate: 10 minutes
Original Estimate - 10 minutes
Remaining Estimate: 10 minutes
Remaining Estimate - 10 minutes
Time Spent: Not Specified
Time Spent - Not Specified




 Description  « Hide

Original post:

Original problem: Column has a not-null constraint and a default of -1. When activerecord tries to create a new instance, it passes NULL instead of -1. This is because postgres returns the default as (-1) and the regex from the function below does not handle numbers with brackets.

we have the lines (@59):

def default_value(value)

  1. Boolean types
    return "t" if value =~ /true/i
    return "f" if value =~ /false/i
  1. Char/String/Bytea type values
    return $1 if value =~ /^'(.*)'::(bpchar|text|character varying|bytea)$/
  1. Numeric values
    return value if value =~ /^-?[0-9]+(\.[0-9]*)?/
  1. Fixed dates / timestamp
    return $1 if value =~ /^'(.+)'::(date|timestamp)/
  1. Anything else is blank, some user type, or some function
  2. and we can't know the value of that, so return nil.
    return nil
    When the negative default value is returned from postgres, it returns, say, "(-1)" inside brackets. However, the above regex for numbers doesn't match on brackets.

Tried to register to log a bug (on, but the server was failing during registration.