how to write this recursive query in Sequel

2018-10-11 Thread genc
Hi, I'm sorry my previous email was mistakenly wrong. This is the correct one. I mixed up the queries. with recursive pattern(pattern) as ( select string_to_array('folder_2/SUB iso', '/') -- input ), full_paths as ( select id, base_folder_id, subject, 1 as idx from folders cross join

Re: how to write this recursive query in Sequel

2018-10-11 Thread genc
PM UTC+3, genc wrote: > > Hi, > > I'm sorry my previous email was mistakenly wrong. This is the correct one. > I mixed up the queries. > > > with recursive pattern(pattern) as ( > select string_to_array('folder_2/SUB iso', '/') -- input > ), > full_paths as ( >

Re: how to write this recursive query in Sequel

2018-10-11 Thread genc
ot; ON (("y"."id" = "pattern" I think In your query, :pattern matched with :y instead of :x with :y when inner join created. I tried to manually fix it but unable to do so. Thanks, Gencer. On Thursday, October 11, 2018 at 10:34:12 PM UTC+3, Jeremy Evans wrote: &g

Re: how to write this recursive query in Sequel

2018-10-12 Thread genc
Thank you so much, Jeremy. Have a great weekend!, Gencer. On Thursday, October 11, 2018 at 9:31:06 PM UTC+3, genc wrote: > > Hi, > > I'm sorry my previous email was mistakenly wrong. This is the correct one. > I mixed up the queries. > > > with recursive pattern

How to append data on existing field

2018-10-22 Thread genc
Hi Jeremy, I am trying to achieve this: update files set name = '--DELETED--' || files.name basically i would like to prepend deleted text to fields. How can I do that with Sequel? I couldn't find any documentation about transforming existing data on the fly with sequel. I tried something

Support for "NOT EXISTS" available?

2018-10-23 Thread genc
Hi Jeremy, I dig into querying.md and can't find any example about "NOT EXISTS". How can we write this query in Sequel: select * from books where not exists (select * from writers where .) Thanks, Gencer. -- You received this message because you are subscribed to the Google Groups

Re: syntax for ORed where clauses?

2018-10-23 Thread genc
Thank you, Jeremy! It did worked. One last question. About migrations. I have a few foreign keys already declared and they are set to "on delete SET NULL". I would like to change them to "on delete CASCADE". I know there was a way of doing this but alter_table seems not mentioned about this.

Re: Support for "NOT EXISTS" available?

2018-10-23 Thread genc
not mentioned about this. How can I change cascade styule for an existing foreign key using migrations? Thanks, Gencer. On Tuesday, October 23, 2018 at 6:28:24 PM UTC+3, Jeremy Evans wrote: > > On Tuesday, October 23, 2018 at 7:46:47 AM UTC-7, genc wrote: >> >> Hi Jeremy, >>

Re: Support for "NOT EXISTS" available?

2018-10-28 Thread genc
Thank you so much, Jeremy. On Tuesday, October 23, 2018 at 5:46:47 PM UTC+3, genc wrote: > > Hi Jeremy, > > I dig into querying.md and can't find any example about "NOT EXISTS". > > How can we write this query in Sequel: > > select * from books where not e

adding more conditions on inner join when using recursive

2018-11-15 Thread genc
Hi Jeremy, I want to add more conditions to inner join after ON but it appends and treat as array instead of merging conditions. Let me show you the full query builder: DB[:full_paths]. select(:id, :subject). cross_join(:pattern). where{{:idx=>cardinality(:pattern)}}. with(:pattern,

Re: adding more conditions on inner join when using recursive

2018-11-15 Thread genc
Ah, I merged them with & Sequel.expr { x[:user_id] =~ 4 } & ... On Thursday, November 15, 2018 at 11:43:03 AM UTC+3, genc wrote: > > Hi Jeremy, > > I want to add more conditions to inner join after ON but it appends and > treat as array instead of merging conditio

querying joined tables and sum all

2019-01-14 Thread genc
Hi Jeremy, Sorry for previous question thread. I deleted it to not confusing. This is what I am trying to do: select sum(sp.storage_size) + sum(bp.storage_size) as storage_size from subscriptions s left join subscription_packages sp on s.subscription_package_id = sp.id left join

Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
trying to join previous join (subscription_packages) not the main 'subscriptions' table .where(user: user) Is there a wiser way to accomplish my query with Sequel? Thanks, Genc. -- You received this message because you are subscribed to the Google Groups "sequel-talk&q

Re: querying joined tables and sum all

2019-01-14 Thread genc
I've achieved this by: .where{ ( subscriptions[:expires_on] =~ nil ) | (subscriptions[:expires_on] <= Time.now.utc) }.sql On Monday, January 14, 2019 at 10:03:38 PM UTC+3, genc wrote: > > Hi Jeremy, > > Sorry for previous question thread. I deleted it to not confusing. > &

Re: Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
I also solved sum field as this: Subscription.select{ (sum( Sequel[:bounty_packages][:storage_size]) + sum( Sequel[:subscription_packages][:storage_size])).as(:size) } Once again, Let me know if there is a better way. On Monday, January 14, 2019 at 8:59:09 PM UTC+3, genc wrote: > > Hi

Re: Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
One thing thsat i couldn't solve is that how to fetch total sum column as :storage_size. select sum() + sum() as FIELD_NAME ... In my scenario, there are two sums and i need to name them. On Monday, January 14, 2019 at 9:36:11 PM UTC+3, genc wrote: > > As per documentation, I ac

Re: Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
[:subscriptions][: bounty_package_id]) .where(user: user) Let me know if there is a better way. Thanks, Genc. On Monday, January 14, 2019 at 8:59:09 PM UTC+3, genc wrote: > > Hi Jeremy, > > This is my SQL query: > > select sum(sp.storage_size) + sum(bp.storage_size) as sto

How to make sure jsonb fields are symbolic hashes when fetched?

2018-12-25 Thread genc
Hi Jeremy, When I do this: class User < Sequel::Model ... end user = User.new user.properties = { name: 'Genc', age: 42 } # or ':name =>..., ' user.save #try to fetch assigned data user.properties[:name] # => Genc user.properties[:age] # => 42 However, If I fetch that data la

Creating master method for models

2018-12-25 Thread genc
Hi Jeremy, I have models like this: class Mailbox::Email < Mailbox::Model(:emails) end class Mailbox::Post < Mailbox::Model(:emails) end and of course a base class: module Mailbox def self.Model(source) c = Sequel::Model(second_db) c.set_dataset(source) end # defining admin?

Re: How to make sure jsonb fields are symbolic hashes when fetched?

2018-12-25 Thread genc
Gotcha. Thanks Jeremy. On Tuesday, December 25, 2018 at 6:37:58 PM UTC+3, genc wrote: > > Hi Jeremy, > > When I do this: > > class User < Sequel::Model > ... > end > > user = User.new > user.properties = { name: 'Genc', age: 42 } # or ':name =>..., '

Re: Creating master method for models

2018-12-25 Thread genc
uesday, December 25, 2018 at 8:50:32 AM UTC-8, genc wrote: >> >> Hi Jeremy, >> >> I have models like this: >> >> >> class Mailbox::Email < Mailbox::Model(:emails) >> end >> class Mailbox::Post < Mailbox::Model(:emails) >> end >> >

Re: Creating master method for models

2018-12-25 Thread genc
no not dataset, connection is wrong. I tried to inbject in method but no luck. Jeremy, How can I inject connection (second_db in this example) using your way? On Tuesday, December 25, 2018 at 10:31:42 PM UTC+3, genc wrote: > > Thanks Jeremy. > > But this time it doesn't se

Re: Creating master method for models

2018-12-25 Thread genc
Thanks Jeremy. It works like a charm. I just able to inject connection. I was missing one line :) On Tuesday, December 25, 2018 at 7:50:32 PM UTC+3, genc wrote: > > Hi Jeremy, > > I have models like this: > > > class Mailbox::Email < Mailbox::Model(:emails) > end >

How to use Where IN "string_to_array" with Sequel?

2019-02-01 Thread genc
Hi Jeremy, On PostgreSQL there is a string_to_array function. This is currently What I am doing: UPDATE files SET date="2007-10-10 10:50:22" WHERE id in(1,2,3,4,5..) However, IDs can be very large and can be oversize for a query. Due to this I woulşd like to send them as text and split

how to add asterisk on count when using partition over

2019-05-23 Thread genc
I have this sql line: count(*) OVER (PARTITION BY sender->>'email') AS "count" And I translated to this: .select_append { count.function.over(partition: sender.get_text('email')).as (:count) } But this gives count() instead of count(*) This causes an error. How can i add asterisk to the

Re: how to add asterisk on count when using partition over

2019-05-23 Thread genc
Ah figured out. .select_append { Sequel.function(:count).*.over(partition: quiz_snapshot. get_text('email')).as(:count) } On Friday, May 24, 2019 at 2:03:54 AM UTC+3, genc wrote: > > I have this sql line: > > count(*) OVER (PARTITION BY sender->>'email') AS "count&q

jsonb, LATERAL and DISTINCT query with sequel

2019-05-24 Thread genc
Hi, Is it possible to write this query with Sequel? SELECT DISTINCT ON (x.e->>'email') x.e->>'email' as email, x.e->>'name' as name FROM messages sr CROSS JOIN LATERAL jsonb_array_elements(sr.receiver) x (e) ORDER BY x.e->>'email', id desc Or I use