# Activerecord generating wrong syntax with postgresql

**URL:** <https://www.ruby-forum.com/t/activerecord-generating-wrong-syntax-with-postgresql/96734>\
**Category:** Rails\
**Created:** [July 1, 2006, 6:21am UTC](https://www.ruby-forum.com/t/activerecord-generating-wrong-syntax-with-postgresql/96734 "2006-07-01T06:21:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [July 1, 2006, 6:21am UTC](https://www.ruby-forum.com/t/activerecord-generating-wrong-syntax-with-postgresql/96734/1 "2006-07-01T06:21:22Z")

</div>

I’m using activerecord outside of rails and find\_first generates sql  
that postgresql doesnt’ like. This is rails 1.1.4, with everything up  
to date via “gem update”.

This is the command line:

ruby -rrubygems seca -c …/etc/seca.cnf cert --export 1 --format  
pkcs12 --key root.key \>root.pfx

This is the error:

(PGError: ERROR: argument of WHERE must be type boolean, not type  
integer  
: SELECT \* FROM certificates WHERE (1) LIMIT 1)

This is the code that generates the error:

bc = SECA::Backend::Certificate.find\_first(options[:certificate\_id])

If I change it to this, it works:

bc = SECA::Backend::Certificate.find(:first, :conditions =\> [“id = ?”,  
options[:certificate\_id]])

And this is the model:  
module SECA  
module Backend  
class Certificate \< ActiveRecord::Base  
STATUS\_VALID = 0  
STATUS\_REVOKED = 1  
STATUS\_EXPIRED = 2  
has\_one :data, :class\_name =\> ‘CertificateData’,  
:foreign\_key =\> ‘certificate\_id’, :dependent =\> true  
#has\_one :serial, :class\_name =\> ‘Serial’, :dependent =\> true,  
# :foreign\_key =\> ‘issuer\_id’  
# User :finder\_sql to find revoked, valid, etc  
has\_many :revoked\_certificates, :class\_name =\> ‘Certificate’,  
:finder\_sql =\> 'SELECT \* FROM certificates WHERE ’ +  
'STATUS = ’ + STATUS\_REVOKED.to\_s  
has\_many :valid\_certificates, :class\_name =\> ‘Certificate’,  
:finder\_sql =\> 'SELECT \* FROM certificates WHERE ’ +  
'STATUS = ’ + STATUS\_VALID.to\_s  
has\_many :certificates, :class\_name =\> ‘Certificate’,  
:foreign\_key =\> ‘issuer\_id’  
has\_many :current\_crl, :class\_name =\> ‘CRL’,  
:finder\_sql =\> 'SELECT id, issuer\_id, last\_update,  
MAX(next\_update) ’ +  
‘AS next\_update FROM crls GROUP BY id’

```
end

```

end  
end
