Posts by Lacobus • 13,510 points
596 posts
-
1
votes2
answers977
viewsA: Python - Find a tuple odd
You can adjust your function to something like: def encontra_impares( tupla ): lista = [] for n in tupla: if n % 2 != 0: lista.append(n) return lista tpl = (1, 2, 3,5,5,9,7,32,1,6) lst =…
-
3
votes1
answer770
viewsA: Turn two data lists into a graph with two parallel lines
You can use the library matplotlib to plot the chart, see only: import matplotlib.pyplot as plt def obterProgresso( linha ): p = [ 0 ] x = 0 for i in linha: if i == 0: x-=1 else: x+=1 p.append(x)…
-
1
votes1
answer289
viewsA: Trigger with sum between dates
The consolidated values table can use the date of the consolidation of the values as its primary key, see only: CREATE TABLE tbl_carteira ( id BIGINT PRIMARY KEY, datat DATETIME, vl_cliente…
-
3
votes2
answers1540
viewsA: Transforming vectors into a Matrix
There is no mystery: matrix = [ [ 1, 2, 3, 4, 5 ], [ 6, 7, 8, 9, 10 ], [ 11, 12, 13, 14, 15 ], [ 16, 17, 18, 19, 20 ] ] print( matrix[2][3] ) Alternatively, you can use the method append(): matrix =…
-
0
votes2
answers1263
viewsA: Run SQL files inside subdirectories on Linux
Assuming your directory tree is something like: $ tree stored-procedures/ stored-procedures/ |-- d1 | |-- sd1 | | |-- sp1.sql | | |-- sp2.sql | | `-- sp3.sql | |-- sd2 | | |-- sp4.sql | | `--…
-
2
votes1
answer152
viewsA: How can I create a dynamic database in Pyhton
In the example below, the Sqlite database is created in the file foobar.db, where a table called tb_fruta is created and its items manipulated (inclusion, alteration and exclusion) through commands…
-
2
votes3
answers238
viewsA: Remove all after ? in file name
You can use the utility find to go through all the files in the tree of a given directory recursively: find ./xyz -type f Each file found would have its name changed with the utility cut: cut -f1…
-
3
votes2
answers201
viewsA: Convert from varchar to float when the string is empty and/or blank
How about using the function translate() combined with nullif() and coalesce(): translate( coalesce( nullif(trim(campo),''), '0,0%') , ',%', '.' )::NUMERIC For example: CREATE TABLE tb_foobar ( id…
-
0
votes2
answers360
viewsA: I cannot import numeric data or dates with empty fields in postgresql
Some fields from your archive CSV of origin seem to be em branco. You need to tell command COPY to interpret these blank fields as if they were NULL, let’s see: COPY ESCOLA_2017 FROM…
postgresqlanswered Lacobus 13,510 -
6
votes1
answer895
viewsA: Measure memory usage in c
You can use the valgrind with the option --leak-check=full. The following program repeatedly allocates and displaces memory blocks via malloc() and free(): #include <stdlib.h> #define…
-
1
votes1
answer41
viewsA: List column of one table with all records of another
Assuming your data structure is something like: CREATE TABLE tb_post ( id BIGINT PRIMARY KEY, title TEXT NOT NULL, category TEXT NOT NULL ); CREATE TABLE tb_post_image ( id BIGINT PRIMARY KEY,…
-
2
votes2
answers112
viewsA: How to make a NOT IN mysql with 2 tables
How about changing your database model to simplify your life ?! I noticed that your problem has 4 distinct entities: Aluno, Materia, Turma and Nota. These four entities may be represented as…
-
1
votes2
answers1079
viewsA: How to disable Trigger for all tables in Postgresql?
You can write a stored Procedure capable of enabling or disabling all triggers of all tables of a given schema, look at you: CREATE FUNCTION fc_habilitar_triggers( nome_schema TEXT, habilitar…
-
-1
votes3
answers992
viewsA: Bring the latest record with conditional - Postgresql
Assuming you have something like: CREATE TABLE tbl_compra ( id BIGINT PRIMARY KEY, nome_prod TEXT NOT NULL, cod_prod BIGINT NOT NULL, cod_cliente BIGINT NOT NULL, data_compra DATE NOT NULL ); INSERT…
-
1
votes1
answer654
viewsA: Random numbers in c++ without repetition
You can fill this vector sequentially and then shuffle its contents, for example: #include <cstdlib> #include <ctime> #include <iostream> int main( int argc, char * argv[] ) { //…
-
1
votes1
answer66
views -
1
votes1
answer1968
viewsA: How to return a table, from a POSTGRES Function?
The problem is not in its function, it is in the way it is being called. When you call your function that way: SELECT public.fc_comparar_comandos( 'ABCD', 'XPTO' ); Postgres returns a single field…
-
0
votes1
answer318
viewsA: How to pick up the percentage of Postgre database storage space via EF Core in Asp.net Core
The physical space, in bytes, occupied by the database SistemaComercial can be calculated using the function pg_database_size(): SELECT pg_database_size( 'SistemaComercial' ); To get the free space…
-
0
votes3
answers1674
viewsA: What is the best way to store videos, audios, images, documents in a bank?
You can store the contents of a file in a column of type BYTEA let’s see: CREATE TABLE tb_arquivo ( id BIGSERIAL PRIMARY KEY, -- Identificador unico do arquivo nome TEXT NOT NULL, -- Nome/Path…
-
2
votes1
answer93
viewsA: Calculating Easter Date in Postgresql
Follows the Easter calculation function in Pg/SQL using the Algorithm by J.M OUDIN: CREATE OR REPLACE FUNCTION data_pascoa( ano INTEGER ) RETURNS DATE AS $BODY$ DECLARE mes INTEGER; dia INTEGER; sec…
postgresqlanswered Lacobus 13,510 -
1
votes3
answers46
viewsA: Group separate table records
SELECT aux.nome, count(1) AS qtd FROM (SELECT f.nome FROM fornecedores AS f WHERE f.ativo = 1 UNION ALL SELECT c.nome FROM clientes AS c WHERE c.ativo = 1 ) AS aux GROUP BY aux.nome; Or simply:…
-
2
votes2
answers495
viewsA: Separate a column of the database in two and take the values of users already created
Assuming your data structure is something like: CREATE TABLE tb_usuario ( id INTEGER PRIMARY KEY, nome_completo TEXT, nome TEXT, sobrenome TEXT ); Test Data: -- DADOS PARA TESTE INSERT INTO…
-
1
votes1
answer453
viewsA: How to read an integer with no limit of digits in C
You can use a buffer of chars large enough to accommodate the integers as a string. Operations with large integers can be done using a library from GNU calling for gmplib. Here is an example where…
-
1
votes2
answers2415
viewsA: SQL query that compares two tables and returns values
Assuming your data structure is something like: CREATE TABLE tb_janeiro ( id BIGINT NOT NULL, txt TEXT NOT NULL, PRIMARY KEY( id ) ); CREATE TABLE tb_fevereiro ( id BIGINT NOT NULL, txt TEXT NOT…
-
4
votes1
answer452
viewsA: Force Postgresql to use an index, how?
Maybe there is nothing wrong, the volume of data in these tables may be responsible for this behavior. Think so: Imagine a book with 5000 pages. The best way to find something specific within that…
-
1
votes2
answers570
viewsA: Create a VIEW or a new TABLE in Postgres?
In your case an index could perfectly solve your problem without the need to create a VIEW. Assuming your data structure is something like: -- INDIVIDUO CREATE TABLE tb_individuo ( id BIGINT NOT…
-
0
votes3
answers3856
viewsA: Return month name as select
Follow another alternative: SELECT (ARRAY[ 'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'])[ EXTRACT(MONTH FROM DATE…
postgresqlanswered Lacobus 13,510 -
0
votes4
answers3044
viewsA: Problem using Setlocale in C
The call of setlocale( LC_ALL, "" ); (with the second blank parameter), causes the default locale of the program to be set automatically according to the environment variables of your system:…
-
5
votes1
answer10401
viewsA: Different timezones in an application with Postgresql
You can change the environment variable TIMEZONE when the application (client) connects to the database. The idea here is: Each customer would be responsible for adjusting their Timezone, and the…
-
1
votes1
answer250
viewsA: Validating only cpfs with different numbers
The function below is able to check whether a string (in the case of a CPF) is composed of a sequence of repeated characters, returns 0 if a sequence is detected: int verificar_sequencia( const char…
-
2
votes3
answers33840
viewsA: C - how to calculate the factorial of a number?
Follows a function (using while) quite simple able to calculate factorial of a number n: unsigned long long fatorial( int n ) { unsigned long long f = 1; while( n > 0 ) f *= n--; return f; } If…
-
2
votes2
answers70
viewsA: Group name into same group
Assuming you have a list of tuples of the type: [ ('JOAO', 10.50), ( 'JOAO', 33.10 ), ('MARCO', 4.00 ), ('JOAO', 15.99), ('MARCO', 21.54) ] How about: vendas = [ ('JOAO', 10.50), ( 'JOAO', 33.10 ),…
-
0
votes2
answers99
viewsA: Problem to remove space after line break
Your program displays the sequence of 1 a X, however, the question statement says nothing about displaying this sequence! Which of the two is correct? To identify values of Y that are multiples of X…
-
0
votes2
answers148
viewsA: Test equal to the question but is giving error
Follows a possible solution to the problem: #include <stdio.h> #include <string.h> #include <stdlib.h> #define SAIDA_MAX_TAM (12) #define SENHA_MAX_TAM (20) char * converter( char…
-
1
votes4
answers9882
viewsA: Program to discover repeated characters in strings and print backwards
You can use a simple function capable of recording the frequency distribution of each character of a given string into an integer vector (see histogram), for example: void strhist( const char * str,…
-
1
votes4
answers528
viewsA: Error Segmentation Fault (Dumped Core) Binary Tree Search
Following his reasoning, follows a solution in C (tested) able to solve your problem, with a more granulated abstraction of entities: árvore binária, of nó and of registro. Note that this is a…
-
1
votes4
answers528
viewsA: Error Segmentation Fault (Dumped Core) Binary Tree Search
Your header ArvoreBinaria.h, has a type definition: typedef struct NO* ArvBin; It means that ArvBin is a ponteiro para um nó, your code makes a tremendous mess of it, for example: ArvBin*…
-
0
votes1
answer65
viewsA: Date field display
You can set an environment variable called DATESTYLE for style GERMAN: SET DATESTYLE = 'GERMAN'; Testing: SELECT current_date; Exit:…
-
2
votes1
answer941
viewsA: Circumvent primary key duplication error
The composite primary key (url, date) table files is already able to maintain data integrity, this TRIGGER is completely unnecessary. However, if the idea is the rapid and massive insertion of data…
-
1
votes4
answers528
viewsA: Error Segmentation Fault (Dumped Core) Binary Tree Search
Note that its function libera_NO() seems to try to compare whether the past node points to null in a strange way, notice well: if(no = NULL) return; libera_NO(no->esq) This is not a comparison!…
-
4
votes5
answers391
viewsA: Concatenation in C
In C, you can use the function sprintf() of the standard library stdio.h to "mount" your command using the format specifier %s in a buffer of chars, for example: char buf[256] = {0} sprintf( buf,…
-
1
votes1
answer2812
viewsA: Configurations environment timezones Django postgres linux
You can set up an environment variable called TIMEZONE, which informs the database the region in which the client connected to the server, this makes the server know how to convert the hours…
-
0
votes1
answer73
viewsA: Choose how many lines you want to show in the output
Based on your reasoning, it follows script modified: #!/bin/bash case "$1" in -r) shuf "$2" ;; -s) sort "$2" ;; *) cat -n "$1" ;; esac Assuming you have an input file called frutas.txt with the…
-
1
votes1
answer70
viewsA: Graphs with noise in the Adian in the plotter
In the plotter: void setup( void ) { Serial.begin(2400); // Inicializa gerador de numeros aleatorios randomSeed(analogRead(0)); // Para cada amostra... for( int velocidade = 0; velocidade <= 50;…
-
0
votes1
answer81
viewsA: Picking up data in pairs in sequential lines
You can use the Haversine’s formula to calculate the distance between two geographical coordinates of your samples: Here is an (tested) example of how to solve your problem: from math import…
-
1
votes1
answer2251
viewsA: C pointers treated in python
Roughly, within the standard Python data model, pointers can be viewed as an analogy to the concept of Identity of Objects, this identity is represented by an integer and can be obtained through the…
-
0
votes1
answer200
viewsA: Save to file . txt (C language)
Based on your reasoning, follow a code (tested) capable of writing to a text file called lista_filmes.txt the content of a lista of filmes: #include <stdlib.h> #include <stdio.h>…
-
6
votes2
answers625
viewsA: Calculate the factorial by reference passage
Calculations Factorial involve Very Large Numbers, and this should be taken into account because in practice the available memory is always finite. More robust codes are able to filter inputs that…
-
1
votes2
answers1597
viewsA: Postgresql Error: "ERROR: there is no Unique Constraint matching Given Keys for referenced table "address""
The entities CLIENTE and ENDEREÇO relate. The cardinality of this relationship is n:n, namely, a CLIENTE may possess none or several ENDEREÇOS registered, and in the same ENDEREÇO, may reside none…
-
3
votes2
answers463
viewsA: Struct definition in C
Your teacher did not "defined a pointer that points to a struct TipoCelula" he named a symbol for the type struct TipoCelula* using typedef. Stay tuned, statement is not the same thing as…