sequel

How to run raw SQL queries with Sequel

让人想犯罪 __ 提交于 2019-11-27 02:47:25
问题 I am not clear yet on the proper way to run raw SQL queries with Sequel. Currently I am trying this: DB.fetch("SELECT * FROM zone WHERE dialcode = '#{@dialcode}' LIMIT 1") do |row| @zonename = row end How can I can run the queries as raw SQL then access the results like normal? if @zonename.name = "UK" 回答1: I have a few pointers which may be useful: You could simply do: @zonename = DB.fetch("SELECT * FROM zone WHERE dialcode = ? LIMIT 1", @dialcode).first NB: you are ignoring the fact that

How to round an average to 2 decimal places in PostgreSQL?

那年仲夏 提交于 2019-11-26 23:48:56
I am using PostgreSQL via the Ruby gem 'sequel'. I'm trying to round to two decimal places. Here's my code: SELECT ROUND(AVG(some_column),2) FROM table I get the following error: PG::Error: ERROR: function round(double precision, integer) does not exist (Sequel::DatabaseError) I get no error when I run the following code: SELECT ROUND(AVG(some_column)) FROM table Does anyone know what I am doing wrong? Craig Ringer PostgreSQL does not define round(double precision, integer) . For reasons @Mike Sherrill 'Cat Recall' explains in the comments, the version of round that takes a precision is only

How to round an average to 2 decimal places in PostgreSQL?

主宰稳场 提交于 2019-11-26 11:55:33
问题 I am using PostgreSQL via the Ruby gem \'sequel\'. I\'m trying to round to two decimal places. Here\'s my code: SELECT ROUND(AVG(some_column),2) FROM table I get the following error: PG::Error: ERROR: function round(double precision, integer) does not exist (Sequel::DatabaseError) I get no error when I run the following code: SELECT ROUND(AVG(some_column)) FROM table Does anyone know what I am doing wrong? 回答1: PostgreSQL does not define round(double precision, integer) . For reasons @Mike