Skip to main content
This endpoint dynamically builds an INSERT statement from the JSON body and executes it against the specified PostgreSQL table. Column names are derived from the object’s keys (get_keys_dict) and values are serialised into the SQL value list (generate_str_of_dict). The newly inserted row is returned via RETURNING *, so the caller immediately receives the full database record — including any auto-generated id, timestamps, or default values.

Endpoint


Path Parameters

string
required
Name of the PostgreSQL table to insert into. Examples: customer, products.

Request Body

Send a JSON object where each key is a column name and each value is the data to insert into that column. The controller uses two helpers to build the SQL:
  • get_keys_dict(data) — extracts the keys in insertion order to form the column list.
  • generate_str_of_dict(data, false) — serialises the values: string values are automatically wrapped in single quotes; numeric values are left bare.
The resulting SQL executed against PostgreSQL is:
string
Full name of the customer (example field).
string
Street address (example field).
string
Contact email address (example field).
string
Phone number (example field).
number
Foreign key to customer_tribute (example field — sent as a number, not quoted in SQL).
number
Foreign key to municipality (example field).
string
Document / identification number (example field).
number
Foreign key to identification_document (example field).
number
Foreign key to legal_organization (example field).
The body fields above correspond to the customer table used in the reference implementation. When inserting into a different table, simply change the keys to match that table’s column names. There is no server-side schema validation — the PostgreSQL driver will reject mismatched columns with a 500 error.

Responses

200 — OK

Returned when rowCount > 0 (the row was inserted successfully).
number
Always 200 on success.
string
"Datos agregados"
object
The full inserted row as returned by RETURNING *. Contains all column values, including database-generated ones such as id or created_at.

404 — Not Found

Returned when rowCount === 0 (the insert ran but affected no rows — unusual for a standard INSERT).

500 — Internal Server Error

Returned on any exception thrown by the pg driver (e.g., a NOT NULL violation, a foreign-key constraint failure, or a connection error).
object
Raw error from the pg driver. Inspect error.code and error.detail for PostgreSQL error specifics.

Examples

Example Response


String quoting is automatic. The generate_str_of_dict helper inspects each value’s JavaScript type before building the SQL string. Values whose typeof is "string" are wrapped in single quotes (e.g., 'Santiago Rivera'); values whose typeof is "number" are inserted as bare literals (e.g., 21). Always send numeric foreign keys as JSON numbers — not as quoted strings — to avoid type mismatches in PostgreSQL.