Bunch of entries on every query on Sequel using SequelRails on Rails.

2020-02-11 Thread xura
Hi, SELECT "pg_attribute"."attname" AS "name", CAST("pg_attribute"."atttypid" AS integer) AS "oid", CAST("basetype"."oid" AS integer) AS "base_oid", format_type("basetype"."oid", "pg_type"."typtypmod") AS "db_base_type", format_type("pg_type"."oid", "pg_attribute"."atttypmod") AS "db_type", pg

Re: Ambiguous fields in joins

2019-11-19 Thread xura
Well, params = [{ Sequel[:stacks][:organization_id] => *@user*.id, Sequel[:stacks][:channel_id] => @channel.id, // or nil }] Solved my problem. Let me know if there is a better way... On Wednesday, November 20, 2019 at 2:21:31 AM UTC+3, xura wrote: &g

Re: Ambiguous fields in joins

2019-11-19 Thread xura
t; IS NULL)) OR (("user_id" = 1) AND ("channel_id" = 5))) AND ("apps"."properties" IS NULL)) On Wednesday, November 20, 2019 at 2:03:20 AM UTC+3, xura wrote: > > SELECT > "stacks".* > FROM "stacks" > INNER JOIN "ap

Ambiguous fields in joins

2019-11-19 Thread xura
SELECT "stacks".* FROM "stacks" INNER JOIN "apps" ON ("apps"."id" = "stacks"."app_id") WHERE "user_id" = 1) AND ("channel_id" IS NULL))) AND ("apps"."properties" IS NULL)) Hi Jeremy, In this query, *user_id* is ambiguous. It exists on both table. How can i make sure its targeted for

Re: How to exclude specific_table.id' s when using join?

2019-09-27 Thread xura
Whoops. .exclude { organizations[:id] =~ excluded_ids } Solved. On Saturday, September 28, 2019 at 2:08:42 AM UTC+3, xura wrote: > > Hi Jeremy, > > I have bucket and bucket_members tables. I join them together and i want > to exclude some bucket.id. > >

How to exclude specific_table.id' s when using join?

2019-09-27 Thread xura
Hi Jeremy, I have bucket and bucket_members tables. I join them together and i want to exclude some bucket.id. excluded_ids = [1,2,3] DB.select { buckets.* } .join(:bucket_members, bucket_id: :id) .where { bucket_members[:user_id] =~ id } .exclude(buckets[:id] =>

Re: FullTextSearch (to_tsquery and to_tsvector in WHERE clause)

2019-08-13 Thread xura
Worked, as always! Thank you Jeremy! On Tuesday, August 13, 2019 at 11:19:30 PM UTC+3, Jeremy Evans wrote: > > On Tuesday, August 13, 2019 at 1:05:12 PM UTC-7, xura wrote: >> >> Hi, >> >> How can I translate this query to Sequel/Ruby? Does Sequel has ability to

Re: FullTextSearch (to_tsquery and to_tsvector in WHERE clause)

2019-08-13 Thread xura
;simple' AS regconfig), (COALESCE("adresses", ''))) @@ t... ^ DETAIL: The input string ended unexpectedly. CONTEXT: JSON data, line 1: On Tuesday, August 13, 2019 at 11:05:12 PM UTC+3, xura wrote: > > Hi, >

FullTextSearch (to_tsquery and to_tsvector in WHERE clause)

2019-08-13 Thread xura
Hi, How can I translate this query to Sequel/Ruby? Does Sequel has ability to handle such queries or do i need to execute raw? SELECT * FROM contacts WHERE to_tsvector('English', addresses ->> 'address') @@ to_tsquery('Heimdall') Thanks! -- You received this message because you are subscrib

Re: Regex in jsonb fields

2019-05-26 Thread xura
Done it. .where(DB.select(1).from{jsonb_array_elements(send_to).as(:t, [:to])}.where (~Sequel.ilike(to.get_text('name'), 'john')).exists) On Sunday, May 26, 2019 at 8:11:41 PM UTC+3, xura wrote: > > One last question here. Sorry for my questions today! Actually

Re: Regex in jsonb fields

2019-05-26 Thread xura
What I've tried so far: .where(DB.select{jsonb_array_elements(send_to)}.exists) But expected output is *SELECT 1* for example. Actual is only SELECT (.. On Sunday, May 26, 2019 at 8:11:41 PM UTC+3, xura wrote: > > One last question here. Sorry for my questions today! Actually two

Regex in jsonb fields

2019-05-26 Thread xura
One last question here. Sorry for my questions today! Actually two question in one row. I have jsonb field which is like this: [ { "name": "Mark", }, { "name": "John", } ] As you can see objects are in single array. I want to search John for example but i want to use regex like "jo*"

Re: how to properly create fields and values with OR

2019-05-26 Thread xura
I was playing with Sequel.| however i missed asterisk there "*". Thank you a million time, Jeremy! You saved my day! On Sunday, May 26, 2019 at 6:10:45 PM UTC+3, xura wrote: > > I have this hash: > > fields = { > name: 'John', > subject: 'He

Re: how to properly create fields and values with OR

2019-05-26 Thread xura
There is also boolean in it: fields = [ { name: 'John', subject: 'Hello', is_ok: true }, { name: 'Mark', subject: 'Hi', is_ok: false } ] On Sunday, May 26, 2019 at 6:10:45 PM UTC+3, xura wrote: > > I have this hash

how to properly create fields and values with OR

2019-05-26 Thread xura
I have this hash: fields = { name: 'John', subject: 'Hello' } And I send this hash by this: Email.where(fields).where(another_condition: 4).all It works, however, When I want to add OR I need to explicitly define them: fields = [ { name: 'John', subject: 'Hello' }, { name:

What is the best way of creating GIN INDEX

2019-05-24 Thread xura
Hi, Following is an :gin index for jsonb fields: CREATE INDEX index_name ON public.emails USING gin (send_cc, send_bcc, send_to, sender); So, in Sequel docs no :Gin mentioned. Is there a better way to do this without writing RAW SQL inside migrations? -- You received this message beca

Re: jsonb, LATERAL and DISTINCT query with sequel

2019-05-24 Thread xura
Thanks Jeremy. It works! On Friday, May 24, 2019 at 5:28:28 PM UTC+3, Jeremy Evans wrote: > > On Friday, May 24, 2019 at 6:22:53 AM UTC-7, xura wrote: >> >> In fact, query is now like this: >> >> SELECT DISTINCT ON (jj->>'email') jj->>'

Re: jsonb, LATERAL and DISTINCT query with sequel

2019-05-24 Thread xura
In fact, query is now like this: SELECT DISTINCT ON (jj->>'email') jj->>'email', jj->>'name' , count(*) over(partition by jj->>'email' ) from emails join lateral jsonb_array_elements(send_to) j(jj) on true ORDER BY jj->>&

Re: jsonb, LATERAL and DISTINCT query with sequel

2019-05-24 Thread xura
text('email')) However, i couldn't properly write this line: CROSS JOIN LATERAL *jsonb_array_elements**(sr.receiver) x (e)* On Friday, May 24, 2019 at 12:55:01 PM UTC+3, xura wrote: > > Hi, > > Is it possible to write this query with Sequel? > >

jsonb, LATERAL and DISTINCT query with sequel

2019-05-24 Thread xura
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 *with_sql?