filtering – Select elements in a list at level 1

Here is the code I tried but failed to achieve what I want.

list={{{-0.678629, -0.247568}, {-0.555433, -0.21052}}, {{0.606745, 
-0.147331}, {-0.246826, 0.426555}}, {{-0.040916, 
   0.329272}, {-0.261357, -0.164607}}, {{0.883787, 
   0.432163}, {-0.555896, 
   0.690923}}, {{-0.00193167, -0.00326776}, {-0.155916, 
   0.0141922}}, {{0.393342, -0.0505961}, {-0.24225, -0.780803}}, 
{{0.194168, 0.196396}, {0.455803, -0.158632}}, {{-0.416166, 
   0.596879}, {0.0341831, 0.000531598}}, {{0.222941, 
   0.0134066}, {-0.107692, -0.59851}}, {{0.390906, -0.24567}, 
{0.146006, 0.393449}}};
 list//Select(#, (#((#))((2))) >= 0 &) &

I want pick an element that every 2nd part of this element at level 1 is greater than 0.

For instance, {{-0.416166, 0.596879}, {0.0341831, 0.000531598}} is suitable because both 0.596879 and 0.000531598 are greater than 0.

databases – Beyond unauthorized data access, what security considerations should I have regarding a user-facing language based on SQL SELECT statements?

I’m considering making a new language based on SQL SELECT statements to allow users to export CSV data in the manner they please. I’m confident in being able to interface this with a permissions system by inspecting the resulting AST from parsing before turning it into a SELECT statement to execute, so I’m not really concerned about this leading to unauthorized data access.

This language would be pretty much a 1-to-1 mapping of SQL SELECT statements, except for a few changes regarding joins and a few other things.

Users are relatively few and can be easily traced and contacted. It’s not the public at large.

The underlying DB would be MariaDB.

What should I be concerned about from this idea? If it’s a bad idea, why?

I thought about the possibility of making a query that doesn’t terminate by using WITH RECURSIVE, so I’m not going to support that syntax, and I made the following question at the DBA SE to see what other ways a SELECT statement could be non-terminating (I thought of a few more while writing that question):

What are all the ways that a SELECT statement could be made to not terminate or take a very long time?

Besides that, is there anything more? Any particular risk? Is it possible to make some type of resource bomb with it, to consume all memory for example?

Access to this language could be put under a permission so only very privileged users could use it, but I wonder if that’s needed.

mysql – What are all the ways that a SELECT statement could be made to not terminate or take a *very* long time?

One way is using WITH RECURSIVE:

WITH RECURSIVE
  t AS (
    SELECT 1 n
    UNION ALL
    SELECT n + 1 FROM t
  )
  SELECT * FROM t;

Joins can be made to return a lot of rows from even small tables.

Tables themselves could be huge.

Views can be done with any such SELECT statement and so SELECT statements that use them may also not terminate.

Is that it? If SELECT statements did not have WITH RECURSIVE syntax, could not do arbitrary joins, were limited to small tables or hard a small LIMIT enforced, and could not use any such view, would they all be guaranteed to terminate in a reasonable time*?

I’m particularly interested in MariaDB/MySQL.

I’m thinking of making a new language based on SQL’s SELECT statements that transpiles/compiles to SQL and I’m wondering what I can do to guarantee query termination in reasonable time*.

* What’s reasonable time is of course subjective. I just mention it to exclude queries that are set to terminate in a time frame so long that we may as well treat it as non-terminating.

performance – MySQL SELECT slow, but only 2 x 300K rows and indexes

Have the MySQL SELECT query below that is awfully slow.

It takes ~1.0 seconds to execute despite have only 300K rows and indexes, so I would love to find a way to get it to execute faster since it’s a query that needs to be run again and again.

The query:

SELECT p.id, p.image, c.name, s.name, MIN(p.saleprice)
FROM products p 
JOIN shops s ON p.shopid = s.id 
JOIN products_category pc ON p.id = pc.product_id 
JOIN categories c ON pc.category_id = c.id
WHERE brand_id > 0
AND pc.category_id = 46
AND pc.active = 1
AND p.price > 0
AND p.saleprice > 0
AND p.saleprice < p.price
AND (last_seen > DATE_SUB(NOW(), INTERVAL 2 DAY))
GROUP BY p.image

The query returns 960 rows.

The table products has 300.000 rows and these columns:

id (int, primary key)
name (varchar 512)
image (varchar 512)
price (int)
saleprice (int)
added (datetime)
last_seen (datetime)

It has one index across multiple columns in this order:

brand_id (int), shopid (int), last_seen (datetime), price (int), saleprice (int)

The table products_categories also has 300.000 rows and these columns:

id (int, primary key)
product_id (int)
category_id (int)
active (int)

It has two indexes across multiple columns:

category_id (int), active (int)
product_id (int), active (int)

Based on similar questions here, I have tried nesting things with an inner select:

SELECT p.id, p.image, c.name, s.name, MIN(p.saleprice)
FROM 
(SELECT * FROM products WHERE brand_id > 0 AND price > 0 AND saleprice > 0 AND saleprice < price AND (last_seen > DATE_SUB(NOW(), INTERVAL 3 DAY))) p 
JOIN shops s ON p.shopid = s.id 
JOIN products_category pc ON p.id = pc.product_id 
JOIN categories c ON pc.category_id = c.id 
WHERE pc.category_id = 46
AND pc.active = 1
GROUP BY p.image

It didn’t help. The version with the inner select takes ~1,3 seconds to execute.

The problem seems to be the join between products and products_category, i.e. the two big tables with 300K rows each.

Maybe there’s a trick I can do with my indexes? Or can any of you spot something else I should optimize?

EXPLAIN of the query:

id  select_type table   partitions  type    possible_keys                   key             key_len ref             rows    filtered    Extra
1   SIMPLE      c       N          const   PRIMARY                         PRIMARY         4       const           1       100.00      Using temporary; Using filesort
1   SIMPLE      pc      N          ref     category_id etc,product_id etc  category_id etc 10      const,const     43104   100.00      Using where
1   SIMPLE      p       N          eq_ref  PRIMARY,brand_id etc            PRIMARY         4       pc.product_id   1       5.00        Using where
1   SIMPLE      s       N          eq_ref  PRIMARY                         PRIMARY         4       p.shopid        1       100.00      N

php – Cargar select con dato que viene por json

estoy trabajando con un modal y para cargar los datos lo estoy haciendo a con json, pero mi problema se gestiona en los siguiente, cuando quiero completar mi combobox NO SE COMO dejar marcado el dato que traigo seleccionado. Mi código es el siguiente, en mi blade tengo lo siguiente

    $('.revisar').click(function (event) {
                event.preventDefault();
                sit = $(this).attr('href');
                url="{{route('ver', ("id"=>"#REF#"))}}";
                url=url.replace("#REF#", $(this).attr('id'));
                $.getJSON(url, {}, function (data) {
                    event.preventDefault();
                    $('#modal').attr('action', sit);
                    $('#ed_md').modal('toggle');

                    if(!data.Estado){
                        alert("Error");
                    }else{
                        $('#nombre').val(data.nombre);
                        $('#email').val(data.email);
                        $('#area').val(data.area);

                        ar = '<select name="areas" id="areas">' +
                                @php
                                    $nwarea = AppModelsArea::where('vigencia', '<', 3)->orderBy('id')->get();
                                @endphp
                                        @foreach($nwarea as $nwareas)
                                    '<option value="{{$nwareas->id}}" @if(**COMO PONER EL DATO SELECCIONADO QUE TRAIGO EN EL (data.area)**==$nwareas->id) selected  @endif>{{$nwareas->area}}</option>' +
                                @endforeach
                                    '</select>';
                        $('#cbo_area').html(ar);
                    }
                });

            });

En mi Controlador, estos son los datos que traigo

public function getAspirantes($id){
        $commit=true;

        if(!is_numeric($id)){
            $commit=false;
            $id="";
            $nombre="";
            $email="";
            $area="";
        }

        if($commit){
            $seleccion = Postulante::where('id', '=', $id)->first();

            if($seleccion==""){
                $commit=false; 
                $id="";
                $nombre="";
                $email="";
                $area="";
            }else{
                $commit = true;
                $id=$seleccion->id;
                $nombre= $seleccion->nombre_completo;
                $email= $seleccion->email_postulante;
                $area=$seleccion->area_id;
            }
        }
    return response()->json(array("Estado"=>$commit, "id"=>$id, "nombre"=>$nombre, "email"=>$email, "area"=>$area), 200, (), JSON_UNESCAPED_UNICODE);
}

A través de este dato $('#cbo_area').html(ar); paso a mi modal el combobox, lo cual me hace, pero no que no me trae es el area que tengo guardada en la base de datos y no se como realizar esto, quizas sea una bobada, pero no se me ocurre. También intente poner en mi modal el combobox, pero llego a lo mismo porque no se como seleccionar el area que corresponde, por fa, ayuda

mariadb – why timezone like ‘+00:00’ ignored with select but error with create table?

I am wondering, why does mariadb ignore timezone like ‘+00:00’ with select statement however throw the error with create table statement?

SELECT CAST('2020-07-09 09:55:36.933554+00:00' AS DATE) dt;

# dt 
2020-07-09

CREATE TEMPORARY TABLE tmp AS 
SELECT CAST('2020-07-09 09:55:36.933554+00:00' AS DATE) dt;

# (1292): Truncated incorrect datetime value: '2020-07-09 09:55:36.933554+00:00'

I read the question about the error and understand how to fix it. Just curious why such not obvious for me behaviour.

javascript – Como meter un select en la parte fc-right de full calendar

Estoy intentando meter un select en la parte derecha de un full calendario al lado de los botones prev y next.

Me he creado una funcion que llamo una vez que hago el render del calendario.

Pero no me introduce el valor en el div.

function establecercentro(){

    var elementoBotonesDerecha = document.getElementsByClassName("fc-right");

    for(var i = 0; i<elementoBotonesDerecha.length ; i++)
    {
       elementoBotonesDerecha(i).innerHTML +=  "<p>hola</p>";
    }

};

En este ejemplo intento meter un p pero en vez de un p seria un select.

macos – How can I select “Allow” from System Preferences -> Security Panel to allow the installer to run from TERMINAL

I am connecting to a MAC OS X computer remotely from my Windows machine. And I am trying to install Docker on the OS X machine. In order to do this, I am running “brew cask install virtualbox” command. However I get an error. From some websites, I learned that I should enable the “Allow” option from System Preferences -> Security and Privacy.

But I can’t do this because I only have access to the terminal (because I am connecting from another machine). I don’t know how to enable this option from the terminal.

Thank you

php – desabilitar um campo a partir de um valor de select

saudações!
estou tentando fazer o seguinte:
no meu campo select tem varios valores dentre eles o outro que só deve ser usado caso o valor não esteja no campo. e um coutro campo de texto que por padrão fica desabilitado e apenas habilita-se caso o usuario clique em outro. tentei deste jeito com Jquery mas sem sucesso. para já conheço muito base de JS e Jquery.
meu script Jquery

$(document).ready(function(){
$(‘#tipo_contac’).on(‘change’,function(){
let tipo_contac = $(this).val();
if(tipo_contac === ‘{{$beneficiario->id}}’)
{
$(‘#outro_cont’).removeAttr(‘disabled’);
}
else
{
$(‘#outro_contac’).attr(‘disabled’,true);
}
});

});

parte do formulario

Nome do Contactante

Seleccione
@foreach($tipo as $beneficiario)
id}}”>{{$beneficiario->tipo_contactante}}
@endforeach

Tipo Contactante

Empresa

Outro Contactante

Select em nomes de uma coluna em uma tabela

Boa noite,

Tenho uma tabela de clientes com muitos registros, gostaria de extrair apenas registros específicos de determinados clientes através do nome.

Ex:

Paulo
Andre
Sandro…..

Como faço?