Posts by Camilo Santos • 1,199 points
47 posts
-
1
votes2
answers61
viewsA: Relation __dir__ method and __getattribute__method
When you run the dir() he needs the __class__ to be able to return the information of the object’s scope. How you reimpled the __getattribute__ forever to return teste, the function does not find…
pythonanswered Camilo Santos 1,199 -
0
votes1
answer199
viewsA: Problem with variables that receive content from a shell command
I added operator usage $() to correctly assign the command output to the variable. To check the variable value the command echo must be executed in the script itself, where the value assigned to the…
-
1
votes2
answers82
viewsA: Python - is it possible to use lambda in print with format (f or .format)?
As already mentioned by Renan, the problem can be solved easier through the use of the ternary operator, however, it is possible to add the lambda along with the print. num = 3000 mil = num//1000 #…
-
2
votes1
answer415
viewsA: Multiple pass to simple parameter in Postgresql
Change your Function to receive a string array in the parameter p_conta declaring him as p_conta character varying[]. This way you can enter multiple values in one variable. In the SQL command in…
-
1
votes1
answer36
viewsA: Help with Update SQL
postgres keeps each database isolated, so if it is connected to the database x you cannot perform queries in the database y. Of course there are resources for communication between different…
-
0
votes1
answer538
viewsA: How can I make a trial to update the balance in postgres?
In postgres to use conditional control of the code flow, the IF ... THEN ... ELSIF ... THEN ... ELSE ... END IF, as documented.…
-
1
votes3
answers54
viewsA: Use of property Nth:Child()
In Nth-Child the first number corresponds to the range to apply the style to the next child element, which in your case will always be 3. The second number can be used to define where the selection…
css3answered Camilo Santos 1,199 -
4
votes2
answers309
viewsA: Get python Documents directory automatically
In the standard python library there is the module os.path which has several methods to assist in handling operating system directories. For you to get the user’s initial (home) directory you can…
pythonanswered Camilo Santos 1,199 -
0
votes1
answer754
viewsA: Dividing sql results in lines through delimiter
Use the function combination string_to_array with the function unnest. string_to_array: converts the reported string in the first parameter to a array separating the elements according to the…
-
2
votes1
answer330
viewsA: Script to change table names in the Postgresql database
You can create an anonymous code block through the clause DO, briefly it is a Function that cannot have return and there is no need to write an object in the database. In Function will be held a…
-
0
votes1
answer227
viewsQ: Map dynamically generated tables in Django by another application
I will develop an application with Django in which it will be necessary to query data in a database that is powered by an ERP (desktop). This ERP generates some drive tables by adding at the end of…
-
1
votes2
answers246
viewsA: Postgres: How to compare json to create audit Trigger and display only differences
I imagine that the use of Trigger would be generic for several tables, in this case I believe it is interesting to have a function to compare the json with the records. This way you can evolve the…
-
0
votes1
answer26
viewsA: Array size in a JSON in Shell Script
Try to remove the []: echo $j | jq -r ".Nomes.nome | length"
-
1
votes1
answer40
viewsA: Generate file D-1
The CURRENT_DATE which returns the current date. If you need the date and time use the CURRENT_TIMESTAMP. select * from ivr_contatos, ivr_campanha, ivr_business where ivr_campanha.id = '1' and…
-
1
votes1
answer1024
viewsA: Script for postgres bank
To make the psql execute the SQL you need to use the parameter -c and inform the string with the command(s) (s). https://www.postgresql.org/docs/current/static/app-psql.html Changing your example…
-
1
votes2
answers343
viewsA: Is there any way to know which tables have Bytea type fields in a Postgresql database?
Among the postgres catalog tables is the pg_attribute which contains column information for all database tables. In this table there is the column atttypid which stores the id of the data type, so…
postgresqlanswered Camilo Santos 1,199 -
1
votes1
answer3125
viewsA: Restore from only one table - Postgresql
How did you dump only one table, the pg_restore would only have an object to restore. Anyway there is the parameter -t to define the tables that will be restored. pg_restore -t…
postgresqlanswered Camilo Santos 1,199 -
2
votes1
answer4525
viewsA: How to handle Null fields in Postgresql
The coalesce is a function that returns the value of the first parameter if it is not null. If null returns the value entered in the second parameter, according to documentation [1]. In the case of…
-
0
votes1
answer181
viewsA: Create query to return the smallest possible value
The use of the extension is common tablefunc with the function crosstab to generate the results in this way. Another alternative is to use the json functions of postgres to generate the results.…
-
2
votes2
answers857
viewsA: Postgresql, Variables for psql functions
Use the EXECUTE, with it you can generate SQL code dynamically in plpgsql. The command EXECUTE runs the SQL command entered in the string. I used the function format to allow the variable to be used…
-
6
votes3
answers8105
viewsA: LIKE and IN command in the same SQL command
You can enter an array containing the beginning of the serial number you want to search as below: select * from estoque where numero_serie like any(array['SCAB171293E29%','SCAB171293E4E%']);…
-
2
votes2
answers2954
viewsA: Search XML field information in SQL
Sqlserver has some functions to extract data from tables with xml fields. https://docs.microsoft.com/pt-br/sql/t-sql/xml/value-method-xml-data-type…
-
3
votes2
answers2203
viewsA: Is a View faster than a regular Query?
To VIEW, among other things, it serves for you to store a complex query in an object in the database, facilitating the reuse of this SQL code. Then every time it is called the SQL code will be…
-
2
votes1
answer4491
viewsA: SQL Server - How to create a new table using a select from another table (Both in the same Database)
Use the clause INTO in your code. The name entered in it will be used in the creation of the new table. SELECT loc.loc_nu_sequencial, CASE WHEN loc.cep IS NULL THEN logr.cep WHEN logr.cep IS NULL…
sql-serveranswered Camilo Santos 1,199 -
0
votes1
answer212
viewsA: jsonb: how to fetch the value of the same key of all objects in an array?
The function jsonb_array_elements expands an array to a set of json values, so you only need to filter these tuples by returning the contents of the key template. If it is necessary to return the…
-
1
votes1
answer70
viewsA: How to not display null values and display values in a row in this condition?
An alternative would be to use WITH for each type of records and then perform a query between them. http://sqlfiddle.com/#! 17/fd98d/16 with funcionario_treinado as ( select issues.id as id,…
postgresqlanswered Camilo Santos 1,199 -
0
votes4
answers17451
viewsA: How to check Postgresql logs?
To identify modifications to the database structure executed by commands DDL, use the resource of EVENT TRIGGER of Postgresql. It is a feature that is available from version 9.3. With it it would be…
-
2
votes1
answer460
viewsA: How to convert day of year to date (without timestamp) [Postgresql]?
A combination of functions may be used to_date and to_char. The function to_date will convert the varchar you own (2016263) on a date. The function to_char will convert that date to the year/month…
-
2
votes2
answers261
viewsA: Update with character in the middle of the string
Ideal is to store only the code and leave the formatting to the frontend, for performance and modeling reasons. To perform this operation, you can use the combination of functions concat and substr…
mysqlanswered Camilo Santos 1,199 -
0
votes2
answers710
viewsA: Operator in postgres function returns SQL Error [42883]: ERROR: operator does not exist: integer = integer[]
Substitute IN for = ANY, with the clause ANY it is possible to check if a value exists in an array. https://www.postgresql.org/docs/current/static/functions-subquery.html CREATE OR REPLACE FUNCTION…
-
0
votes1
answer123
viewsA: How to find the most updated tuple in postgres?
Remove the field data_chegada of group by, this way the reference of each vehicle and the maximum date will be returned. SELECT relatorio_viagem_veiculo.referencia_veiculo,…
-
4
votes1
answer410
viewsA: Displaying quarterly data up to the current POSTGRESQL date
This is because in where you were filtering exactly this situation: only "divisible" months for 3. AND cast(to_char("HistoricoIndicador"."dt_criado",'mm') as int) % 3 = 0 If I understand correctly,…
postgresqlanswered Camilo Santos 1,199 -
2
votes2
answers1083
viewsA: Sort a. csv file from the numeric column
Use the module csv (https://docs.python.org/3.6/library/csv.html) I performed the tests using python3. import csv with open ("freq.csv", "r") as f: dados = csv.reader(f, delimiter=";") # Com o…
-
1
votes2
answers2740
viewsA: Adding up POSTGRESQL values
If you are using postgres version 9.4 or higher, you can use the FILTER clause, which uses less code than CASE and follows the SQL standard 2003. Below is an example: select sum(problemas) filter…
postgresqlanswered Camilo Santos 1,199 -
0
votes1
answer136
viewsA: Fill null field with first previous null field
Since your table will always keep this sequence, a function can be done that first stores the code and when this field is null it uses the previously saved variable. Below is an example: do $$…
postgresqlanswered Camilo Santos 1,199 -
1
votes2
answers837
viewsA: How to generate UUID’s/GUID’s with Javascript?
I did some research and found some functions that might help you. To generate UUID you can use the function below: function create_UUID(){ var dt = new Date().getTime(); var uuid =…
-
1
votes1
answer52
viewsA: What command is being misused in this script?
As a variable has not yet been assigned a value ALVO you cannot refer to it with "$". Since the variable is empty when using it with the command grep an error is returned. #!/bin/bash read ALVO…
shell-scriptanswered Camilo Santos 1,199 -
6
votes2
answers7292
viewsA: Filter elements from a Python list
Can also be used List Comprehension, it consumes less machine resources than filter() or map(), but the result is exactly the same. lista = [2, 3, 1, 5, 1, 7, 8, 8, 9, 15, 1, 1] lista = [l for l in…
pythonanswered Camilo Santos 1,199 -
1
votes1
answer244
viewsA: Insertion of dates in Postgresql
Willian, postgres has the parameter datestyle which allows you to configure the default date format of your cluster (if configured in postgresql.conf) or your database (ALTER DATABASE database_name…
-
2
votes3
answers1770
viewsA: Increase word size, placeholder attribute value of text inputs?
Can be done with CSS, the syntax changes depending on the browser. Following example: <!DOCTYPE html> <html> <head> <style> input:-ms-input-placeholder { font-size:16px; }…
-
1
votes2
answers12845
viewsA: How to get the names of all Postgresql database tables?
One of the alternatives is to use the postgres catalogues. Catalog tables have a format more suitable to postgres as specific types of SGDB and possibility of using some functions. select…
-
1
votes1
answer105
viewsA: Django does not create admin.py file in new app
Wilker, Probably the version of Django you are using, I am with version 1.10 and the admin.py file is created. Also check in the file py Settings. in INSTALLED_APPS if there is the value…
-
4
votes1
answer94
viewsA: WHERE in bigint field[]
Rafael, You can use the &&operator, it compares two array and if any element exists in the two it returns true (as if it were an "OR"). Assuming this permissa_ver field is a bigint[], you…
-
1
votes1
answer328
viewsA: Transfer JSON table columns in Postgres Trigger
To perform this action you will need to use the function row_to_json. This function will transform the entire row (Row) into a json object: the "key" will be the column name and the "value" the…
-
-2
votes1
answer419
viewsA: Can I use Css within a Swing application?
Some things can be done in the component. Below is an example of using CSS and HTML for a Jbutton: jbBotao = new javax.swing.JButton(); jbBotao.setText("<html>\n<style>\ndiv {\ncolor:…
-
-1
votes1
answer1250
viewsA: How to search for similar words or synonyms in Postgresql
Rafael, I believe you will achieve this using Full Text Search. http://www.postgresql.org/docs/current/static/textsearch.html select * from tabela where to_tsvector('portuguese', campo_text) @@…
-
1
votes1
answer1063
viewsA: Form for Foreignkey Relationship
Sara, To link only one attribute I use Foreignkey. Objects of this type are generated by Jango as a combobox (Forms.Select). If you need to pass a specific object just inform it in your view. In the…
djangoanswered Camilo Santos 1,199