postgresql

Vapor 3 PostgreSQL CRUD without requests http

六眼飞鱼酱① 提交于 2021-01-27 14:48:24
问题 I am creating backend based on Vapor 3.1.10 using Xcode 11.2 and Swift 5.1, database is PostgreSQL 12. I have a question: how to interact with database (CRUD) without POST and GET requests. All tutorials show how to CRUD only based on Request through HTTPS. But what if my app needs to save something in database without interacting with network? Look at my code: import Vapor import FluentPostgreSQL final class Device: PostgreSQLModel { var id: Int? var isWorking: Bool var serial: Int init

Is it possible to add a constraint to a Postgres table using rounded values for latitude and longitude?

笑着哭i 提交于 2021-01-27 13:48:24
问题 I have a table that stores latitude and longitude data. Something like the following: CREATE TABLE geo_sample ( id uuid DEFAULT uuid_generate_v4 (), latitude FLOAT NOT NULL, longitude FLOAT NOT NULL, PRIMARY KEY (id) ); After a while, we realized that we didn't want to allow geographical coordinates to be entered that are too close to one another, so we thought we could use a constraint to help enforce this. My thinking was that if we rounded the coordinates to n decimal places, that would

Can Postgres use a function in a partial index where clause?

谁说胖子不能爱 提交于 2021-01-27 13:29:55
问题 I have a large Postgres table where I want to partial index on 1 of the 2 columns indexed. Can I and how do I use a Postgres function in the where clause of a partial index and then have the select query utilize that partial index? Example Scenario First column is "magazine" and the second column is "volume" and the third column is "issue". All the magazines can have same "volume" and "issue" #'s but I want the index to only contain the two most recent volumes for that magazine. This is

How to make the copy command continue its run in redshift even after the lambda function which initiated it has timed out?

自闭症网瘾萝莉.ら 提交于 2021-01-27 13:25:06
问题 I am trying to run a copy command which loads around 100 GB of data from S3 to redshift. I am using the lambda function to initiate this copy command every day. This is my current code from datetime import datetime, timedelta import dateutil.tz import psycopg2 from config import * def lambda_handler(event, context): con = psycopg2.connect(dbname=dbname, user=user, password=password, host=host, port=port) cur = con.cursor() try: query = """BEGIN TRANSACTION; COPY """ + table_name + """ FROM '"

How to list each pair of tuple only once irrespective of column order in SQL and relational algebra?

倖福魔咒の 提交于 2021-01-27 13:15:56
问题 I'm working on some book exercises and can't find an explanation on how to express the following in relational algebra. I did find an answer for SQL though but I'm interested in whether there are any alternatives to solve it. The question from the book is: Find those pairs of PC models that have both the same speed and RAM. A pair should be listed only once; e.g., list(i,j) but not (j,i). The schema for PC is: PC ( model INTEGER NOT NULL PRIMARY KEY, speed NUMERIC, ram INTEGER, hd INTEGER,

Database creation not working in eclipselink with glassfish 4 and Postgres

别来无恙 提交于 2021-01-27 13:11:33
问题 I want to create the database based on Entities. Configuration: Glassfish: GlassFish Server Open Source Edition 4.1 (build 13) Eclipselink: Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd (delivered with glassfish) Database: PostgreSQL Version: 9.4.2 Driver: PostgreSQL Native Driver Version: PostgreSQL 9.4 JDBC4.1 (build 1201) From the moment eclipselink starts creating the database I see the following statements in the logs after putting a lot of log parameters on finest: SELECT ID

How to update with incrementing value

a 夏天 提交于 2021-01-27 13:06:50
问题 I have a table in PostgreSQL that has an ID column that is supposed to be unique. However, a large number of the rows (around 3 million) currently have an ID of "1". What I know: The total number of rows The current maximum value for the ID column The number of rows with an (incorrect) ID of "1" What I need is a query that will pull all the rows with an ID of "1" and assign them a new ID that increments automatically so that every row in the table will have a unique ID. I'd like it to start

Conditional update with jsonb_set()

南笙酒味 提交于 2021-01-27 13:05:58
问题 I have a table in a Postgres 11.3 database with a jsonb column. Trying to update all objects inside a nested array name "iProps" . If the path {iProps -> value -> rules -> ao -> sc} is an object, then the path should be updated from an object to a string with the value {iProps -> value -> rules -> ao -> sc -> name} If the path {iProps -> value -> rules -> ao -> sc} is not present, then the object should be left unchanged. Test setup with query: Fiddle link Desired result: { "iProps": [ {

psycopg2 register_composite from sqlalchemy

纵然是瞬间 提交于 2021-01-27 12:56:58
问题 is it possible to somehow use function register_composite from psycopg2, when i am using sqlalchemy to connect to postgresql database? My problem is that I want SQLAlchemy to handle custom composite type that i created in postgresql like this: CREATE TYPE card AS (value int, suit text); Sqlalchemy returns me values of this type as an string and I would like to somhow learn sqlalchemy my new type. If found some information about creating custom composite types in SQL alchemy ORM, but I am

Django ORM raw delete query not deleting records

混江龙づ霸主 提交于 2021-01-27 12:55:02
问题 I am using raw_sql queries for my convenience for keeping my database minimal I am deleting extra records. By this query #d is from a loop and has values res=MyModel.objects.raw("DELETE FROM mydb_mymodel WHERE mydb_mymodel.s_type = '%s' and mydb_mymodel.barcode = '%s' and mydb_mymodel.shopcode = '%s' and mydb_mymodel.date = '%s'" ,[d.s_type,d.barcode,d.shopcode,d.date]) It is not deleting records in database but when I do res.query and run it from postgres console it works! Yes I can use