postgresql-9.3

Left Join Lateral and array aggregates

夙愿已清 提交于 2019-12-08 01:48:48
问题 I'm using Postgres 9.3. I have two tables T1 and T2 and a n:m relation T1_T2_rel between them. Now I'd like to create a view that in addition to the columns of T1 provides a column that, for each record in T1, contains an array with the primary key ids of all related records of T2. If there are no related entries in T2, corresponding fields of this column shall contain null-values. An abstracted version of my schema would look like this: CREATE TABLE T1 ( t1_id serial primary key, t1_data int

How to return rows of query result in PostgreSQL's function?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 01:38:48
问题 I've tried following tutorials for many times but failed. Could someone give me some examples please? Here is my code, it prompts that "ERROR:invalid type name 'SETOF RECORD'" create or replace function find() returns SETOF RECORD as $$ declare A SETOF RECORD; begin A=( select x,y from ....... ) CASE WHEN EXISTS A THEN returns query A ELSE returns query ( select x,y from ...... ) END; end; $$ language plpgsql; 回答1: Ways to declare set returning function that I remember at the moment: -

How to make build system for PostgreSQL

ε祈祈猫儿з 提交于 2019-12-07 20:15:09
问题 Making build system for MS SQL Server is easy: { "cmd": ["sqlcmd", "-S", ".", "-i", "$file"], "selector": "source.sql", "shell": true } and for PostgreSQL I tried this: { "env": {"PGPASSWORD": "password"}, "cmd": ["C:/PostgreSQL/9.3/bin/psql.exe", "-U", "postgres", "-f", "$file"], "selector": "source.postgresql", "shell": true } But, while with MS SQL I can reference database from the script with USE keyword, there is no such feature in Postgre so above build can't work, and it seems to me I

Postgres UTC to Java ZonedDateTime

偶尔善良 提交于 2019-12-07 14:59:04
问题 Follow-up question to my original issue. Because I know that any date time used is against a known timezone, rather than where the user may be submitting their request from, I take a LocalDateTime, convert to UTC and persist. Then, when the appointment is retrieved I convert the saved time to the meeting location timezone (stored in db). However, it would seem that the values I save are actually being saved in my local timezone. I receive a date time value in the Rest Controller such as:

PostgreSQL 9.3: Pivot table query

一笑奈何 提交于 2019-12-07 13:27:27
问题 I want to show the pivot table(crosstab) for the given below table. Table: Employee CREATE TABLE Employee ( Employee_Number varchar(10), Employee_Role varchar(50), Group_Name varchar(10) ); Insertion: INSERT INTO Employee VALUES('EMP101','C# Developer','Group_1'), ('EMP102','ASP Developer','Group_1'), ('EMP103','SQL Developer','Group_2'), ('EMP104','PLSQL Developer','Group_2'), ('EMP101','Java Developer',''), ('EMP102','Web Developer',''); Now I want to show the pivot table for the above data

How to specify host name in pg_hba.conf file of postgresql?

笑着哭i 提交于 2019-12-07 12:01:08
问题 We want to create a line like this : host all all vs1.nsdp.ir md5 in pg_hba.conf file. But it doesn't understand this host name. It's Ip is 192.168.1.60 and when we use ip address that's fine. But it won't work with host name. 回答1: We created a reverse dns lookup in our dns server so it can be able to reverse lookup the ip of our domain and the problem is solved 来源: https://stackoverflow.com/questions/22374768/how-to-specify-host-name-in-pg-hba-conf-file-of-postgresql

Why does pg_restore return “options -d/--dbname and -f/--file cannot be used together”?

邮差的信 提交于 2019-12-07 06:19:43
问题 The following Windows batch script fails on the line with database restore: @Echo off set Path=C:\Program Files (x86) set Backup_Path=C:\Program Files (x86) c: cd \ cd C:\Program Files (x86)\PostgreSQL\9.1\bin @echo "Wait ..." setlocal set PGPASSWORD=1234 psql.exe -U postgres -c "create database Mydata" "C:\Program Files (x86)\PostgreSQL\9.1\bin\pg_restore.exe" -h localhost -U postgres -d Mydata -f "Mydata.backup" pause endlocal The error is: pg_restore : -d / - dbname and -f / - file can not

Can someone explain how Postgresql roles, Postgresql users and Linux users relate to each other?

点点圈 提交于 2019-12-07 04:41:20
问题 I am trying to setup Postgres 9.3 on an Ubuntu 14 server, and I'm feeling pretty demoralised at this point. I've previously used MySQL, so I'm happy with general database concepts, as well as client/server models etc. I start with two users - 'root' and 'sam' (me). As 'sam' I install postgresql using apt-get. This also creates a third user called 'postgres'. Fine. I'm told that to use postgres you must be logged in as the postgres user, so I switch to that account. Apparently this comes with

How to upgrade PostgreSQL with PostGIS?

心已入冬 提交于 2019-12-07 04:01:00
问题 I was running PostgreSQL 9.1 and I am trying to upgrade to PostgreSQL 9.3: $ /usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf" However it fails with: Checking for presence of required libraries fatal Your installation references loadable libraries that are

How to install PL/Python on PostgreSQL 9.3 x64 Windows 7?

寵の児 提交于 2019-12-07 03:50:46
问题 I have tried to install the PL/Python v2.x language inside PostgreSQL on my database running the query: CREATE EXTENSION plpythonu; (I got this from http://www.postgresql.org/docs/9.3/static/plpython.html) But I'm getting this error: ERRO: não pôde acessar arquivo "$libdir/plpython2": No such file or directory ********** Error ********** ERRO: não pôde acessar arquivo "$libdir/plpython2": No such file or directory SQL state: 58P01 How to install this in an automated way? I need to install it