Skip to content

Commit

Permalink
Merge pull request #33 from jcsjcs/deparse_limit
Browse files Browse the repository at this point in the history
Deparse LIMIT and OFFSET.
  • Loading branch information
lfittl committed Aug 27, 2015
2 parents 6c8cb61 + 37eef89 commit 88fab84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/pg_query/deparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,16 @@ def deparse_select(node) # rubocop:disable Metrics/CyclomaticComplexity
end.join(', ')
end

if node['limitCount']
output << 'LIMIT'
output << deparse_item(node['limitCount'])
end

if node['limitOffset']
output << 'OFFSET'
output << deparse_item(node['limitOffset'])
end

output.join(' ')
end

Expand Down
10 changes: 10 additions & 0 deletions spec/lib/pg_query/deparse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@
let(:query) { "SELECT a, b, max(c) FROM c WHERE d = 1 GROUP BY a, b" }
it { is_expected.to eq query }
end

context 'LIMIT' do
let(:query) { "SELECT * FROM x LIMIT 50" }
it { is_expected.to eq query }
end

context 'OFFSET' do
let(:query) { "SELECT * FROM x OFFSET 50" }
it { is_expected.to eq query }
end
end

context 'type cast' do
Expand Down

0 comments on commit 88fab84

Please sign in to comment.