postgresql-9.2

Creating partial unique index with sqlalchemy on Postgres

女生的网名这么多〃 提交于 2019-12-17 16:14:00
问题 SQLAlchemy supports creating partial indexes in postgresql. Is it possible to create a partial unique index through SQLAlchemy? Imagine a table/model as so: class ScheduledPayment(Base): invoice_id = Column(Integer) is_canceled = Column(Boolean, default=False) I'd like a unique index where there can be only one "active" ScheduledPayment for a given invoice. I can create this manually in postgres: CREATE UNIQUE INDEX only_one_active_invoice on scheduled_payment (invoice_id, is_canceled) where

What is the maximum number of columns in a PostgreSQL select query

蓝咒 提交于 2019-12-17 02:37:35
问题 Do you know what the maximum number of columns that can be queried in Postgresql? I need to know this before I start my project. 回答1: According to About PostgreSQL it's "250 - 1600 depending on column types". See "Limits". The column types affect it because in PostgreSQL rows may be at most 8kb (one page) wide, they cannot span pages. Big values in columns are OK because TOAST handles that, but there's a limit to how many columns you can fit in that depends on how wide the un-TOASTed data

ERROR: function expression in form cannot refer to other relations of same query level : How to work around LATERAL

∥☆過路亽.° 提交于 2019-12-13 08:02:34
问题 DROP SCHEMA tmp CASCADE; CREATE SCHEMA tmp ; SET search_path=tmp; CREATE TABLE primes ( pos SERIAL NOT NULL PRIMARY KEY , val INTEGER NOT NULL , CONSTRAINT primes_alt UNIQUE (val) ); CREATE FUNCTION is_prime(_val INTEGER) RETURNS BOOLEAN AS $func$ DECLARE ret BOOLEAN ; BEGIN SELECT False INTO ret WHERE EXISTS (SELECT * FROM primes ex WHERE ex.val = $1 OR ( (ex.val * ex.val) <= $1 AND ($1 % ex.val) = 0 ) ); RETURN COALESCE(ret, True); END; $func$ LANGUAGE plpgsql STABLE; CREATE VIEW vw_prime

PostgreSQL 9.2.4 - Desire to Change the Localhost Server Password in Mavericks & Databases

跟風遠走 提交于 2019-12-13 05:06:36
问题 Currently PostgreSQL 9.2.4 is provided in OSX Mavericks. I have used the provided PostgreSQL since running Lion Server. When I started using it I was using a password that I now realize is not very secure. I am having trouble finding the right command to do this. The user/role (I supposed) that is provided is _postgres. This is the password I would like to change. I attempted the command below but honestly I'm not sure what it is supposed to do. I thought that this would allow me to access

single quotes appear arround value after running copy in postgres 9.2

混江龙づ霸主 提交于 2019-12-13 03:08:30
问题 I am new to postgres and I play around with data loading. Here is the table definition from postgres 9.2 spec: CREATE TABLE weather ( city varchar(80), temp_lo int, -- low temperature temp_hi int, -- high temperature prcp real, -- precipitation date date ); I prepared the following data file (weather.txt): San Francisco 43 57 0.0 '1994-11-29' Hayward 54 37 0.0 '1994-11-29' and ran the COPY command: COPY weather FROM '~aviad/postsgres/playground/weather.txt'; now, when I run select * from

Assigning default value for type

不问归期 提交于 2019-12-13 00:25:27
问题 How to assign default value to following type of Oracle statement into PostgreSQL 9.3? CREATE OR REPLACE FUNCTION(.... ... DECLARE v_var Table01.column01%TYPE := 'SLOW'; BEGIN ... ... END; 回答1: Postgres allows to provide parameter defaults , which kick in for missing parameters in the function call. Only allowed for parameters at the end of the list . Example: CREATE OR REPLACE FUNCTION foo ( param1 int , v_char tbl01.col01%TYPE DEFAULT 'foo' ) ... -- no need to DECLARE anything else. BEGIN .

Postgresql “no pg_hba.conf entry” error

你说的曾经没有我的故事 提交于 2019-12-12 18:09:46
问题 I'm setting up my local postgresql database for a rails project (that I'm joining), and have done the following: Installed postgres Added/bundled 'pg' gem Created a db user named "foobar" Created a db named "foobar_development" The rails app comes with a rake db:migrate task. When I run this task, I get the following error output: FATAL: no pg_hba.conf entry for host "::1", user "foobar", database "foobar_development", SSL off I found a pg_hba.conf file in the following location: /usr/local

Postgresql and Oracle: update multiple tables from common subquery

左心房为你撑大大i 提交于 2019-12-12 05:26:09
问题 Hello i have got 4 tables first table is menu have got column: Id number PK parent_id number FK to menu.Id title character varying(250) softdel boolean default false second table is page : id as PK menu_id as FK to menu.id page_id as FK to page.id softdel boolean default false third table is article : id as PK and FK to page.id softdel boolean default set to false and fourth table article_lang : partial_id as PK id as FK to article.id language character softdel boolean default set to false

Is it possible to create “Insensitive Table and Column name” in PostgreSQL

旧城冷巷雨未停 提交于 2019-12-11 16:52:22
问题 I am working on PostgreSQL 9.2 and i want to create a table with capital letter without using double quotes.Is it possible by any how? means CREATE TABLE STUDENT(NAME VARCHAR(50)); i want the table name must be look like "STUDENT" But postgresql automatically convert it into "student". So is there any way exist to disable sensitive property of postgresql for column and table names? thank you. 来源: https://stackoverflow.com/questions/23217205/is-it-possible-to-create-insensitive-table-and

Psycopg2 Installing, Not Being Read by Python - OS 10.8.4, Python 2.7, PostgreSQL 9.2

眉间皱痕 提交于 2019-12-11 16:48:55
问题 OS 10.8.4, Python 2.7, PostgreSQL 9.2 I've been spending the past 10+ hours trying to get Psycopg2 installed for Django and am now receiving warnings and a failure that Google can't seem to help me with: After cleaning out all existing Psycopg2 & PostgreSQL files, reinstalling PostgreSQL 9.2 and Python 2.7, I was still getting the _PQbackendPID error when trying to install Psycopg2 with Pip. So I tried changing the ARCHFLAGS setting on install: $ sudo env ARCHFLAGS="-arch i386 -arch x86_64"