postgresql

Postgresql regexp_matches syntax not working as expected

邮差的信 提交于 2021-02-17 06:40:34
问题 I use the Postgres regexp_matches function to extract numbers. The regular expression I use is 4([\s\-\/\.]*?0){3}([\s\-\/\.]*?[12]){1}([\s\-\/\.]*?\d){4} If I use a tool like https://regexr.com/ to verify if it's working and I apply the following test set 4-0001-1234 5-2342-2344 499999999 4-0001-1234 4.0001.12344 4-0-0-0-1-1234 I get the expected extraction result: 4-0001-1234 4-0001-1234 4.0001.1234 4-0-0-0-1-1234 However, if I use the same expression in Postgresql, it does work well:

Postgresql regexp_matches syntax not working as expected

本小妞迷上赌 提交于 2021-02-17 06:39:08
问题 I use the Postgres regexp_matches function to extract numbers. The regular expression I use is 4([\s\-\/\.]*?0){3}([\s\-\/\.]*?[12]){1}([\s\-\/\.]*?\d){4} If I use a tool like https://regexr.com/ to verify if it's working and I apply the following test set 4-0001-1234 5-2342-2344 499999999 4-0001-1234 4.0001.12344 4-0-0-0-1-1234 I get the expected extraction result: 4-0001-1234 4-0001-1234 4.0001.1234 4-0-0-0-1-1234 However, if I use the same expression in Postgresql, it does work well:

Postgres: granting access to a role/user for future tables created by a different role/user

我只是一个虾纸丫 提交于 2021-02-17 06:13:20
问题 I'm building a spring boot application. Flyway database migrations are executed at the application startup. I decided to use two different roles: role__app ( read/write rights on tables, sequences in app schema) and role__migration ( advanced rights in app / migration schemas). Flyway migrations are executed under role__migration so it becomes the owner of the created objects. I thought that the following statements would help: ALTER DEFAULT PRIVILEGES IN SCHEMA app GRANT SELECT, INSERT,

function UNIX_TIMESTAMP does not exist

断了今生、忘了曾经 提交于 2021-02-17 06:12:14
问题 I am trying to convert my datetime to unix timestamp. I've tried doing several ways and the error is all the same. I am not very sure what I am suppose to do. date_joined is like this 2017-09-30 10:24:44.954981+00:00 function unix_timestamp(timestamp with time zone) does not exist HINT: No function matches the given name and argument types. You might need to add explicit type casts. User.objects.annotate(photo_time=Func(F('date_joined'),function='UNIX_TIMESTAMP')) User.objects.extra(select={

Postgresql - IN clause optimization for more than 3000 values

烈酒焚心 提交于 2021-02-17 06:07:51
问题 I have an application where the user will be uploading an excel file(.xlsx or .csv) with more than 10,000 rows with a single column "partId" containing the values to look for in database I will be reading the excel values and store it in list object and pass the list as parameter to the Spring Boot JPA repository find method that builds IN clause query internally: // Read excel file stream = new ByteArrayInputStream(file.getBytes()); wb = WorkbookFactory.create(stream); org.apache.poi.ss

Postgresql - IN clause optimization for more than 3000 values

∥☆過路亽.° 提交于 2021-02-17 06:05:04
问题 I have an application where the user will be uploading an excel file(.xlsx or .csv) with more than 10,000 rows with a single column "partId" containing the values to look for in database I will be reading the excel values and store it in list object and pass the list as parameter to the Spring Boot JPA repository find method that builds IN clause query internally: // Read excel file stream = new ByteArrayInputStream(file.getBytes()); wb = WorkbookFactory.create(stream); org.apache.poi.ss

Postgresql - IN clause optimization for more than 3000 values

江枫思渺然 提交于 2021-02-17 06:04:28
问题 I have an application where the user will be uploading an excel file(.xlsx or .csv) with more than 10,000 rows with a single column "partId" containing the values to look for in database I will be reading the excel values and store it in list object and pass the list as parameter to the Spring Boot JPA repository find method that builds IN clause query internally: // Read excel file stream = new ByteArrayInputStream(file.getBytes()); wb = WorkbookFactory.create(stream); org.apache.poi.ss

how to get user input from qdateEdit and select it from database in postgres

夙愿已清 提交于 2021-02-17 04:00:32
问题 i want to know how to get the user input in QDateEdit and select it in a table in postgres? here is my code def date(self): try: date = self.dateEdit.date() print(date) conn = psycopg2.connect(dbname="sample", user="postgres", password="admin", host="localhost", port="5432") cur = conn.cursor() cur.execute("SELECT * FROM data WHERE stdate = '%s'",date) result = cur.fetchall() self.tableWidget.setRowCount(0) for row_number, row_data in enumerate(result): self.tableWidget.insertRow(row_number)

Sqlalchemy duplicated WHERE clause to FROM

本秂侑毒 提交于 2021-02-17 03:40:17
问题 I wrote raw query to psql and it's work fine but when i wrote this in sqlalchemy my WHERE clause duplicated to FROM clause. select id from T1 where arr && array(select l.id from T1 as l where l.box && box '((0,0),(50,50))'); In this query i fetch all id from T1 where array with ints intersects with results from subquery. class T1(): arr = Column(ARRAY(Integer)) ... class T2(): box = Column(Box) # my geometry type ... 1 verison: layers_q = select([T2.id]).where(T2.box.op('&&')(box)) # try find

How to change the schema by arg text in postgres procedure

我只是一个虾纸丫 提交于 2021-02-17 03:37:53
问题 CREATE OR REPLACE FUNCTION newfunction (Schema1 text, Schema2 text) RETURNS integer LANGUAGE plpgsql SECURITY DEFINER AS $function$ . . . insert into [Schema1].table (name,phone,address,......) select name,phone,address,..... from [Schema2].table where....; I want to change the schema by arg text is this possible to do this? 回答1: You'll have to use dynamic SQL throughout: EXECUTE format( E'INSERT INTO %I.tab (...)\n' 'SELECT ... FROM %I.tab WHERE ...', schema1, schema2 ); 来源: https:/