Can I write PostgreSQL functions on Ruby on Rails?

后端 未结 2 1168
故里飘歌
故里飘歌 2020-11-30 09:49

We are starting a project based on Ruby on Rails. We used to work with Perl and PostgreSQL functions, and with Rails and Active Record I\'ve not seen how we are supposed to

2条回答
  •  北海茫月
    2020-11-30 10:38

    If your only requirement is creating them somewhere in your Rails app, this is possible through ActiveRecord::Base.connection.execute, which you can use to execute raw SQL queries.

    stmt = 'CREATE FUNCTION...'
    ActiveRecord::Base.connection.execute stmt
    

    You would then call the function using ActiveRecord::Base.connection.execute as well (I'd imagine you'd have methods in your model to handle this).

提交回复
热议问题