postgresql

How to reduce result rows of SQL query equally in full range?

假装没事ソ 提交于 2021-01-28 19:10:43
问题 I have values related to dates. I need to select data for example for 10 years. Standard query result has approximately 3000 rows, but I need to show them on graph with 400px width and send them over the rest api to mobile phone. So it would be nice to reduce the data to let's say 400 values. Is there any build in method how to reduce data equally in full range in SQL Server or PostgreSQL? How should I do this? 回答1: In Postgres , width_bucket() is just the thing you are looking for - to

How to run the python application and postgres in one docker container?

风流意气都作罢 提交于 2021-01-28 18:56:32
问题 I have a python application that interacts with the postgresql database and i need to run it all in one docker container. I get a connection error when running the container: ... File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/lib/python3.6/asyncio/base_events.py", line 787, in create_connection ', '.join(str(exc) for exc in exceptions))) OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 5432), [Errno 111] Connect call

PostgreSQL ST_AsMVT to VectorTiles to Leaflet Layer

旧时模样 提交于 2021-01-28 18:44:50
问题 I'm trying to create vector tiles from a PostgreSQL database and serve them via flask to a Leaflet map. I've followed this medium.com article which got me nearly all the way. However, when i open the page with the Leaflet map on it I get the following in the browser console: index.js:191 Uncaught Error: Unimplemented type: 4 at Pbf.skip (index.js:191) at Pbf.readFields (index.js:41) at new VectorTile$1 (vectortile.js:8) at FileReader. (Leaflet.VectorGrid.Protobuf.js:124) to create the tiles I

Using variables in SQL script

时光毁灭记忆、已成空白 提交于 2021-01-28 15:14:25
问题 I am writing a unit test for my PostgreSQL functionality. This starts with inserting data in the database and then calling a certain function. However, because I use auto-incrementing IDs, I cannot know what parameter to put in my function call. I want to be able to do something like this: INSERT INTO myTable ...; SELECT id FROM myTable INTO l_id; SELECT my_function(l_id); Updates I am using an SQL script, not PL/pgSQL In MySQL I can do this: SELECT @id:=itemid FROM myTable; , then later on,

Write to a file from RAISE NOTICE in postgresql

时光毁灭记忆、已成空白 提交于 2021-01-28 15:11:06
问题 I have one sample function in postgresql and it raises a notice. Sample function - CREATE OR REPLACE FUNCTION raise_test() RETURNS TEXT AS $body$ DECLARE retStr TEXT; BEGIN SELECT current_timestamp into retStr; RAISE NOTICE '%', retStr ; RETURN retStr; END; $body$ LANGUAGE plpgsql; Is there any way to update above function so that the entire notice stored into a file? Like if I hit "call raise_test();" and in my specfic location I 'll have one out.txt with the entire notice printed. PS. I hv

Using variables in SQL script

喜夏-厌秋 提交于 2021-01-28 15:01:55
问题 I am writing a unit test for my PostgreSQL functionality. This starts with inserting data in the database and then calling a certain function. However, because I use auto-incrementing IDs, I cannot know what parameter to put in my function call. I want to be able to do something like this: INSERT INTO myTable ...; SELECT id FROM myTable INTO l_id; SELECT my_function(l_id); Updates I am using an SQL script, not PL/pgSQL In MySQL I can do this: SELECT @id:=itemid FROM myTable; , then later on,

Write to a file from RAISE NOTICE in postgresql

我是研究僧i 提交于 2021-01-28 14:59:38
问题 I have one sample function in postgresql and it raises a notice. Sample function - CREATE OR REPLACE FUNCTION raise_test() RETURNS TEXT AS $body$ DECLARE retStr TEXT; BEGIN SELECT current_timestamp into retStr; RAISE NOTICE '%', retStr ; RETURN retStr; END; $body$ LANGUAGE plpgsql; Is there any way to update above function so that the entire notice stored into a file? Like if I hit "call raise_test();" and in my specfic location I 'll have one out.txt with the entire notice printed. PS. I hv

org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = bytea

随声附和 提交于 2021-01-28 14:38:46
问题 I am trying to execute a Native Query from a Spring Boot application, but i am getting this error " org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = bytea " Here are the codes i have written to implement this @SqlResultSetMapping( name = "StudentAssessmentValue", classes = @ConstructorResult( targetClass = StudentAssessmentDTO.class, columns = { @ColumnResult(name = "subject_title", type = String.class), @ColumnResult(name = "assessment", type = String.class), } )

Double quote in the name of table in select query of PostgreSQL

假如想象 提交于 2021-01-28 14:34:16
问题 I am running following simple select query in PostgreSQL: SELECT * FROM "INFORMATION_SCHEMA.KEY_COLUMN_USAGE" It gives me following error report: ERROR: relation "INFORMATION_SCHEMA.KEY_COLUMN_USAGE" does not exist LINE 1: SELECT * FROM "INFORMATION_SCHEMA.KEY_COLUMN_USAGE" ^ ********** Error ********** ERROR: relation "INFORMATION_SCHEMA.KEY_COLUMN_USAGE" does not exist SQL state: 42P01 Character: 15 But when I am running the following query it runs successfully: SELECT * FROM INFORMATION

SQL value of previous (unknown) date

自作多情 提交于 2021-01-28 14:30:12
问题 I have a table with articles, Day Date, and amount of bought. I want a reslut table where I can see the amount off all Articles and how many where bought and the amount they where bought at the unknown date before: Example result of: select articleid, amount, date from table1 where articleid in(7,8) |------------|---------|----------| | articleid | amount | date | |------------|---------|----------| | 7 | 34 |20.10.2019| |------------|---------|----------| | 7 | 2 |15.10.2019| |------------|-