On Wednesday, January 8, 2020 at 8:00:36 AM UTC-8, BeeRich33 wrote:
>
> My PG syntax has a variable into an interval:
>
> WHERE creation_date::timestamp::date > (CURRENT_DATE - interval '$1 days'
> )::date
>
 
That's interesting, it's not something I would expect to work because the 
placeholder is inside an SQL string.  It certainly doesn't work when using 
psql:

> PREPARE foo AS SELECT (CURRENT_DATE - interval '$1 days')::date;
PREPARE
> EXECUTE foo(2);
    date
------------
 2020-01-07
> EXECUTE foo(10);
    date
------------
 2020-01-07

Can you provide some example ruby code that shows this variable working? I 
can only assume it's some ruby library using broken interpolation.
 

> Can I use a variable in Sequel as a parameter passed to this method, for 
> use inside this interval integer?
>
> Sequel.cast('? days', 30, :interval)
>

You could probably do this type of string interpolation in Ruby:

num_days = 30
Sequel.cast("#{num_days} days", :interval)

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/ef96a338-5b67-4fdb-83a4-123e180a6464%40googlegroups.com.

Reply via email to