-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong pog.Date
format causes crash
#54
Comments
Ok this was due to a wrong format for the date... |
We certainly don't want to crash! Could you share a reproduction for the crash please 🙏 |
Sure, with the following code snippet: import gleam/option.{Some}
import pog
pub fn main() {
let db =
pog.default_config()
|> pog.host("localhost")
|> pog.database("postgres")
|> pog.user("postgres")
|> pog.password(Some("postgres"))
|> pog.pool_size(15)
|> pog.connect
let create_table_query =
"
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
some_date DATE
)
"
let assert Ok(response) =
pog.query(create_table_query)
|> pog.execute(db)
let insert_query =
"
INSERT INTO test (some_date)
VALUES ($1)
"
let assert Ok(response) =
pog.query(insert_query)
|> pog.parameter(pog.date(pog.Date(31, 01, 2025)))
|> pog.execute(db)
pog.disconnect(db)
} You should get the following error:
I was parsing a date in the format |
pog.Date
format causes crash
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
When using pog to insert data into PostgreSQL nullable columns, passing an empty string ("") causes a runtime error. This is a common issue with PostgreSQL drivers since PostgreSQL treats empty strings differently from NULL values. Currently, pog crashes with an Erlang error instead of handling this case gracefully.
Current Behavior
When attempting to insert an empty string into a nullable PostgreSQL column:
The empty string is passed directly to PostgreSQL
pog crashes with an Erlang error:
Expected Behavior
There are two potential solutions to consider:
Steps to Reproduce
Create a PostgreSQL table with a nullable column:
Create an insert query:
Attempt to insert a record with an empty string for the nullable field:
For a quick reproduction, you can clone this repo:
Additional Context
Technical Details
pog version: 3.2.0
PostgreSQL version: 17
Gleam version: 1.6.2
The text was updated successfully, but these errors were encountered: