Skip to content

Support non-string parameters and default values #149

@ipamo

Description

@ipamo

Passing non-string parameters and default values can be achieved today using something like:

select *
where grade >= cast(%(grade)s as integer)
and is_allowed = cast(coalesce(nullif(%(is_allowed)s,''), 'true') as boolean)

But this is not very readable. Would be nice to support some other patterns, for example:

select *
where grade >= %(grade)d
and is_allowed = %(is_allowed:true)b

I know that psycopg2 supports only string parameters, but it does not seem too difficult to manually handle simple cases (like numbers and booleans) while still caring about SQL injections.

For now, I've proposed pull request #148 to refactor the named-parameter feature within the library, so that developpers can easily extend it according to their needs. That would be usefull in any case.

I think it would also be usefull that simple cases (like those mentionned above) be part of the library. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions