postgresql

Connecting to Google Cloud SQL instance on private IP from a VM with both private and public IPs fails

荒凉一梦 提交于 2020-12-04 05:17:33
问题 What I'm trying to set up: Cloud SQL instance with private IP, Postgresql database A VM with one public IP and one private IP on same VPC network as the SQL instance is on (VM, SQL instance and VPC are all in the same region) VM has a service account with sufficient Cloud SQL client/viewer permissions SQL proxy on VM connecting to SQL instance. I run it with the -ip_address_types=PRIVATE argument I've found in some of the documentation. Configuration code Slightly simplified Terraform code

SELECT EXISTS vs. LIMIT 1

那年仲夏 提交于 2020-12-04 03:18:30
问题 I see SELECT EXISTS used a lot like: if db.query(""" SELECT EXISTS ( SELECT 1 FROM checkout WHERE checkout_id = %s ) """ % checkout_id).getresult()[0][0] == 't': vs. what i prefer: if db.query(""" SELECT 1 FROM checkout WHERE checkout_id = %s LIMIT 1 """ % checkout_id).getresult(): Which one is preferred and why? P.S. i am using Python and PosgreSQL. cert=> explain SELECT EXISTS (SELECT 1 FROM checkout WHERE checkout_id = 3); QUERY PLAN --------------------------------------------------------

SELECT EXISTS vs. LIMIT 1

99封情书 提交于 2020-12-04 03:18:11
问题 I see SELECT EXISTS used a lot like: if db.query(""" SELECT EXISTS ( SELECT 1 FROM checkout WHERE checkout_id = %s ) """ % checkout_id).getresult()[0][0] == 't': vs. what i prefer: if db.query(""" SELECT 1 FROM checkout WHERE checkout_id = %s LIMIT 1 """ % checkout_id).getresult(): Which one is preferred and why? P.S. i am using Python and PosgreSQL. cert=> explain SELECT EXISTS (SELECT 1 FROM checkout WHERE checkout_id = 3); QUERY PLAN --------------------------------------------------------

Postgres: Expand JSON column into rows

我是研究僧i 提交于 2020-12-02 06:59:21
问题 In a Postgres 9.3 database I have a table in which one column contains JSON, as in the test table shown in the example below. test=# create table things (id serial PRIMARY KEY, details json, other_field text); CREATE TABLE test=# \d things Table "public.things" Column | Type | Modifiers -------------+---------+----------------------------------------------------- id | integer | not null default nextval('things_id_seq'::regclass) details | json | other_field | text | Indexes: "things_pkey"

How do you do UUID in Golangs Gorm?

不羁岁月 提交于 2020-12-02 06:11:32
问题 I have the following model... type User struct { ID string `sql:"type:uuid;primary_key;default:uuid_generate_v4()"` FirstName string `form:"first_name" json:"first_name,omitempty"` LastName string `form:"last_name" json:"last_name,omitempty"` Password string `form:"password" json:"password" bindind:"required"` Email string `gorm:"type:varchar(110);unique_index" form:"email" json:"email,omitempty" binding:"required"` Location string `form:"location" json:"location,omitempty"` Avatar string

how do I convert text to jsonB

青春壹個敷衍的年華 提交于 2020-12-01 09:13:52
问题 What is the proper way to convert any text (or varchar) to jsonB type in Postgres (version 9.6) ? For example, here I am using two methods and I am getting different results: Method 1: dev=# select '[{"field":15,"operator":0,"value":"1"},{"field":15,"operator":0,"value":"2"},55]'::jsonb; jsonb ---------------------------------------------------------------------------------------------- [{"field": 15, "value": "1", "operator": 0}, {"field": 15, "value": "2", "operator": 0}, 55] (1 row) Method

how to properly specify database schema in spring boot?

给你一囗甜甜゛ 提交于 2020-12-01 08:56:34
问题 in my spring boot / hibernate application, I need to connect to a Postgres database "ax2012_1", which belong to the "dbo" schema. I have the following application.properties: # Database db.driver: org.postgresql.Driver db.url: jdbc:postgresql://localhost:5432/ax2012_1 db.username: my_user_name db.password: my_password spring.datasource.url= jdbc:postgresql://localhost:5432/ax2012_1 spring.datasource.username=my_user_name spring.datasource.password=my_password spring.datasource.schema=dbo

how to properly specify database schema in spring boot?

末鹿安然 提交于 2020-12-01 08:55:10
问题 in my spring boot / hibernate application, I need to connect to a Postgres database "ax2012_1", which belong to the "dbo" schema. I have the following application.properties: # Database db.driver: org.postgresql.Driver db.url: jdbc:postgresql://localhost:5432/ax2012_1 db.username: my_user_name db.password: my_password spring.datasource.url= jdbc:postgresql://localhost:5432/ax2012_1 spring.datasource.username=my_user_name spring.datasource.password=my_password spring.datasource.schema=dbo

how to convert integer minutes to interval in postgres

左心房为你撑大大i 提交于 2020-12-01 08:24:53
问题 I'm trying to convert minutes which are in integer to interval in postgres Is their any function that will help me to convert it to interval or should i have divide it by 60 and get the final result 20 minutes will be like 00:20:00 as result 回答1: Fastest way is with make_interval make_interval(years int DEFAULT 0, months int DEFAULT 0, weeks int DEFAULT 0, days int DEFAULT 0, hours int DEFAULT 0, mins int DEFAULT 0, secs double precision DEFAULT 0.0) So it looks like this (as suggested by

How to clone a test database from a production one in one single action?

眉间皱痕 提交于 2020-12-01 03:24:23
问题 I am looking for a basic script/command that will create a copy of a live database (let name them mydb and mydb_test , both on the same server). Requirements it has to run even if the mydb_test already exists and have records it has to work even if mydb and mydb_test do have existing connections it have to clean the potentially existing database if necessary Hints: drop database cannot be used if you have existing connections 回答1: The simplest and fastest method to create a complete copy of