Posts by anonimo • 4,084 points
322 posts
-
0
votes2
answers150
viewsA: Select with IN operator in array column in Postgres
Use the appropriate array operator, in this case OVERLAPS: SELECT titulo, ids_autores FROM tb_livros WHERE ids_autores && ARRAY[10,15]; If one of the elements, 10 or 15, exists in the array.…
-
-3
votes2
answers1140
viewsA: How to make an Insert with columns and values coming from a select?
INSERT INTO table SELECT * FROM table WHERE t = "12:00:00";
-
2
votes2
answers240
viewsA: How to sort a table according to data from another table
SELECT tb1.cd_tb1, AVG(tb2.vl_avaliacao) FROM tb1 LEFT OUTER JOIN tb2 ON (tb1.cd_tb1 = tb2.cd_tb1) GROUP BY tb1.cd_tb1 ORDER BY tb1.cd_tb1; Perhaps it might be in your interest to use:…
-
1
votes1
answer224
viewsA: Postgres: Error converting date in Postgres 10
Because as of version 10 you have rejected invalid dates. See Release Notes (Appendix E): https://www.postgresql.org/docs/current/release-10.html E.9.3.6. Functions Make to_timestamp() and to_date()…
-
3
votes1
answer81
viewsA: type of incompatible pointer
When you declare x[] x it can be considered as a pointer. When does: int *ponteiro = &x; in reality is assigning the address of the address. In your case do: int *ponteiro = x;…
-
3
votes2
answers555
viewsA: Command SQL PARTITION BY?
Partitioning a table means dividing a table, which is logically large, into several physically small tables in order to improve the performance of applications that use the database. For example you…
-
3
votes1
answer1115
viewsA: How to create COLLATION for Brazilian Portuguese
pt_BR.utf8 To check which locales are available use: SELECT * FROM pg_collation;
-
1
votes1
answer117
viewsA: prime numbers between a sequence
Your test to check if cousin is wrong. Try: for (teste=1;teste<=contador;teste++) { bash=0; div = 1; while(div <= teste) { if (teste%div == 0) { bash++; } div++; } if (bash==2) {…
-
2
votes5
answers114
viewsA: Logical error while using If/Else
This test: if ((A + B < C) || (B + C < A) || (A + C < B)) { is invalid to test whether the 3 values can represent a triangle. In a triangle each side is smaller than the sum of the other…
-
2
votes4
answers126
viewsA: Can I put a WHERE for each column?
One option to do this count is: SELECT SUM(CASE cor_casa = 'azul' THEN 1 ELSE 0 END) AS casaAzul, SUM(CASE cor_casa = 'amarela' THEN 1 ELSE 0 END) AS casaAmarela FROM tb_casa;…
-
2
votes2
answers136
viewsA: What is the difference between memcpy and snprintf
They’re not the same. The memcpy function copies n bytes from the memory position pointed by the first parameter to the positions from the address of the second parameter. The snprintf function…
-
0
votes3
answers107
viewsA: Help with string programming logic?
As it is a single character: scanf("%s",&chave); for: scanf("%c", &chave); Note that you will have problems if the key does not exist in the string and there is also confusion between…
-
0
votes2
answers541
viewsA: IF/ELSE in SQL (Control Structures)
The SQL language itself does not have an IF/ELSE command. You will find such a command in procedural languages associated with your database manager. In SQL you can use the CASE/WHEN condional: CASE…
-
0
votes2
answers46
viewsA: Convert character
void converte_minusculo(char s[]) { int posicao = 0; while (s[posicao] != '\0') { if (s[posicao] >= 'A' && s[posicao] <= 'Z') { s[posicao] = s[posicao] - 'A' + 'a'; } posicao++; } }…
-
-1
votes3
answers437
viewsA: Postgresql 8 - Replace the first occurrence of a character in a string
Version 8.0 was no longer supported in October/2010. Upgrade your installation to a newer version. The current version is 10.3 which will receive support until October/2022.
postgresqlanswered anonimo 4,084 -
0
votes1
answer346
viewsA: Delete records with multiple conditions
DELETE ba1 FROM bid_account ba1, bid_account ba2, WHERE ba1.auction_id = ba2.auction_id AND ba1.bidding_price = ba2.bidding_price AND ba1.max_id < ba2.id AND ba1.bid_flag = 'd' AND…
-
-1
votes1
answer2383
viewsA: How to sort two vectors (ascending order ) into a third vector using only one loop?
#include <stdio.h> int main() { int i, j=0, k=0, a[5]={1,4,8,9,11}, b[5]={3,6,7,10,15}, c[10]; for(i=0; i<10; i++) { if (a[j] < b[k]) { c[i] = a[j]; j++; } else { c[i] = b[k]; k++; } for…
-
1
votes1
answer68
viewsA: Error in the conversion of numerical bases
The memory space used by an integer (32 bits) can store numbers in the range of -2,147,483,647 up to 2,147,483,647. To work with a longer range use the long long type instead of int. Note that the…
-
0
votes3
answers53
viewsA: For each value of a table show the corresponding if no zero is shown
Substitute: FROM vendedores INNER JOIN for: FROM vendedores LEFT OUTER JOIN…
-
0
votes1
answer245
viewsA: C separate string with commas in vectors
In its vector structure you define two pointers: a char pointer (date) and another pointer to long int (value). To effectively store the read values you need to allocate the required space and have…
-
1
votes1
answer90
viewsA: printing calendar with wrong days
This test of yours: month_days[1] = (ano%4 == 0 || ano%400 == 0 && ano%100 != 0) ? 29 : 28; is wrong. Right is right: month_days[1] = (((ano % 4 == 0) && (ano % 100 != 0)) || (ano %…
-
0
votes2
answers2415
viewsA: SQL query that compares two tables and returns values
Search by EXCEPT operator. https://www.postgresql.org/docs/current/static/queries-union.html "EXCEPT Returns all Rows that are in the result of Query1 but not in the result of query2. (This is…