Skip to content

Where with parametrized INTERVAL #379

@ikawalec

Description

@ikawalec

Hi,

I'm having an issue with using where expr with parametrized INTERVAL.

Code:

d := 3

builder := r.StatementBuilderType.
  Delete("test").
  Where(squirrel.Expr("expiry <= now()::timestamptz - INTERVAL '? DAYS'", d))
		
query, args, err = builder.ToSql()
	
logrus.Infof("query: %s, args: %+v", query, args)
	
// db execute

I'm getting the following error:

ERROR: could not parse "$1 DAYS" as type interval: interval: missing number at position 0: "$1 DAYS" (SQLSTATE 22007)

Generated query and args:

query: DELETE FROM test WHERE expiry \u003c= now()::timestamptz - INTERVAL '$1 DAYS'
args: [3]

Expected SQL:

delete from test where expiry <= now()::timestamptz - INTERVAL '3 days';

Is this a bug? Is there any other way this can be achieved?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions