Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/sequel/adapters/redshift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ def adapter_initialize
end

def table_exists?(name)
relation_exists?(name, 'r')
end

def view_exists?(name)
relation_exists?(name, 'v')
end

# @param [String] relkind 'r' for table, 'v' for view
def relation_exists?(name, relkind)
sql = <<~SQL
SELECT EXISTS (
SELECT * FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'public'
AND c.relname = '#{name}'
AND c.relkind = 'r'
AND c.relkind = '#{relkind}'
);
SQL
fetch(sql).first.fetch(:"?column?")
Expand Down