How to INSERT in a table that is in a Postgres schema with Sequel?

39 Views Asked by At

According to the Sequel document, this is the syntax to insert data into DB.

DB[:items].insert
# INSERT INTO items DEFAULT VALUES

If the table items is created in some_schema. The SQL command is

INSERT INTO some_schema.items DEFAULT VALUES

What is the syntax when using Sequel? I tried some ways but it doesn't work.

E.g

DB[:some_schema][:items].insert
DB[:some_schema.items].insert
1

There are 1 best solutions below

0
Khuyen Ho On

After researching, I found a way. We need to connect with DB and set the search path to the schema.

DB = Sequel.connect(adapter, host, database, search_path: "some_schema", user, password)

And then you can call direct to the table items, not some_schema.items anymore.