How Can I use group by when strict mode = true in laravel? - eloquent

I can not use group by in strict=true. I don't want to change strict and I want to use group by. How Can I use it?
$subjects = SyllabSubjectCompetency::with([
'subject'
])->wherehas('syllab', function($query) use($center_syllab_id){
$query->where('syllab_id', $center_syllab_id);
})->groupBy('subject_id')->get();
It returns
"SQLSTATE[42000]: Syntax error or access violation: 1055 'let_us_learn_dev.syllab_subject_competencies.id' isn't in GROUP BY
When I change strict mode true to false then it works. But I dont want to change strict. Is it possible and How?

Related

Is there a way to do this without CASE expression?

I would like to avoid so often using CASE expressoin, especially for not so complicated logic like here. Is there a better way?
CASE
WHEN lower(player_status::text) in ( 'active'::text,'live'::text)
THEN true
ELSE false
END
Can I get the same output without CASE?
Thanks!
Actually you don't need the CASE expression.
You can directly select the boolean expression:
SELECT COALESCE(lower(player_status::text), '') IN ('active'::text, 'live'::text)
FROM ...
The function COALESCE() is used to prevent the expression to return NULL in case player_status is NULL.
If player_status is not nullable it can be omitted:
SELECT lower(player_status::text) IN ('active'::text, 'live'::text)
FROM ...
So I gather the end result you are looking for is a list of usernames and user statuses, but for users having the status "active" or "live" you wish to display the boolean true instead of the value actually stored in the database, right? The accepted answer works, but personally I find it a little easier to read using select constants:
SELECT name, true as player_status
FROM players.player_data
WHERE player_status IN ('active', 'live')
This will present only active/live players and their status will be displayed as true. If you need the query to return all players, regardless of status, while still making the text substitution for active players, you can simply union together the above query with its inverse, though I'm not sure this is any less complex or readable than the other two proposed solutions in this thread:
SELECT name, true as player_status
FROM players.player_data
WHERE player_status IN ('active', 'live')
UNION ALL
SELECT name,false
FROM players.player_data
WHERE (player_status is null)
OR (player_status NOT IN ('active', 'live'))
That all said, personally, I'd probably make this substitution at the UI layer, not in the database query, which would make the whole matter moot, though that's more a matter of personal preference than.

Vert.x WildcardPermissionBasedAuthorization .match returns false

I'm having trouble understanding how WildcardPermissionBasedAuthorization works (docs)
The following code returns false, which as far as I know means that the user is not authorized, though I would expect at least one of these 'or' authorizations to match the wildcard one of "t*"
User user = User.create(new JsonObject().put("username", "testUser"));
user.authorizations().add("", PermissionBasedAuthorization.create("test"));
user.authorizations().add("", WildcardPermissionBasedAuthorization.create("t*"));
OrAuthorization or = OrAuthorization.create();
or.addAuthorization(PermissionBasedAuthorization.create("t"));
or.addAuthorization(PermissionBasedAuthorization.create("te"));
or.addAuthorization(WildcardPermissionBasedAuthorization.create("t"));
or.addAuthorization(WildcardPermissionBasedAuthorization.create("te"));
or.addAuthorization(WildcardPermissionBasedAuthorization.create("te*"));
or.match(user); //is false
What I'm trying to achieve is give my user access to anything that starts with 't', and then in my handler assert whether the user has access to 'te'
thanks,
Fil
Ok, turns out you can put a wildcard for an entire colon-delimited section only, like
"newsletter:edit:*"
from here

How to get permission to change run-time parameter?

In this wonderful answer is proposed GUC-pattern to use run-time parameters to detect current user inside trigger (as one solution). It seemed to suit to me too. But problem is: when I declare the variable in postgresql.conf it is usable inside trigger and I can access it from queries, but can't change it:
# SET rkdb.current_user = 'xyzaaa';
ERROR: syntax error at or near "current_user"
LINE 1: SET rkdb.current_user = 'xyzaaa';
The error message is misleading, so I did not dig it a while, but now it seems this user (database owner) has no permissions to change params set in global configuration.
I can set any other params:
# SET jumala.kama = 24;
SET
And read it back:
# SHOW jumala.kama;
jumala.kama
-------------
24
(1 row)
I can't SHOW globally set params:
# SHOW rkdb.current_user;
ERROR: syntax error at or near "current_user"
LINE 1: SHOW rkdb.current_user;
^
but I can reach it with current_setting() function:
# select current_setting('rkdb.current_user');
current_setting
-----------------
www
(1 row)
So my guess is, my database owner does not have permissions to access this param. How could I:
set needed permissions?
or even better
set run-time params with database owner rights?
current_user is an SQL standard function, so your use of that name confuses the parser.
Either use a different name or surround it with double quotes like this:
rkdb."current_user"

How can I turnoff case sensitive matching from Vertica ? Either Globally or session wise

Can I turn case-sensitive data handling from Vertica off session wise . I want it to be dependent on user who may either want to keep it case-sensitive or otherwise !
Also Is there any key to be modified while logging in to mark the session on for Unicode data handling ?
There are indeed ways. I did not test them fully, so there might be corner cases I am not aware of. The keyword you are looking for is collation. You specifically want to update the colstrength keyword and you want a value of 1 I believe (case and accents are ignored).
You can do it in a few ways:
vsql-only : \locale en_US#colstrength=1
from anywhere including via ODBC/JDBC statements: SET LOCALE TO 'en_US#colstrength=1';
by overriding the Locale value in your DSN (not tested) usually in /etc/odbc.ini for odbc
To show the effect, here is an example, first with the default, then after changing the locale:
\locale
en_US#collation=binary
select 'me' = 'ME';
?column?
----------
f
(1 row)
SET LOCALE TO 'en_US#colstrength=1';
\locale
en_US#colstrength=1
select 'me' = 'ME';
?column?
----------
t
(1 row)
I am pretty sure there is more to it, but this should get you started.

Sphinx SetSortMode EXPR

I am trying to sort using Sphinx (PHP) to show in order of price but when I do it will show £10 before £1.75 so I need to use ABS like in mySQL.
I have tried this:
$s->SetSortMode (SPH_SORT_EXPR, "ABS(display_price) ASC" );
It doesnt seem to work though.
Can anybody help?
Check, if display_price attribute treated as a decimal in search index
Probably you have
sql_attr_string = display_price
instead of
sql_attr_float = display_price
or
sql_attr_bigint = display_price
updated
SPH_SORT_EXPR is ALWAYS descending order. the ASC/DESC are for use with EXTENDED mode only.
To 'invert' it to become acsending, can build it into the expression.
$s->SetSortMode (SPH_SORT_EXPR, "1000000-CEIL(ABS(display_price*100.0))" );