postgresql-9.3

PostgreSQL 9.3: Split one column into multiple

梦想的初衷 提交于 2019-12-25 04:11:25
问题 I want to split one column that is colb in the given below example into two columns like column1 and column2 . I have a table with two columns: Example : create table t3 ( cola varchar, colb varchar ); Insertion: insert into t3 values('D1','2021to123'), ('D2','112to24201'), ('D3','51to201'); I want to split the colb values into two columns like the following expected result: Expected Result : cola column1 column2 --------------------------------- D1 2021 123 D2 112 24201 D3 51 201 回答1: select

CakePhp does not work in Ubuntu 14.04

风流意气都作罢 提交于 2019-12-25 02:29:01
问题 I have installed cakephp v2.4.6 in Ubuntu 14.04 (64 bit) and database is PostgreSQL. The same system works fine in Windows environment but after I transfer it into Ubuntu, it shows some issues. The CSS does not work. No color and the login screen alignment change. After login, an error says "the requested url was not found in the server" came. Some forum ask us to change the config file in /etc/apache2/sites-available/default.conf . But I could not find any default.conf file. Please guide.

Psycopg ppygis select query

拥有回忆 提交于 2019-12-24 22:30:31
问题 I'm trying to setup a basic working postgis setup with python ppygis package. >>> import psycopg2 >>> import ppygis >>> connection = psycopg2.connect(database='spre', user='postgres') >>> cursor = connection.cursor() >>> cursor.execute('CREATE TABLE test (geometry GEOMETRY)') >>> cursor.execute('INSERT INTO test VALUES(%s)', (ppygis.Point(1.0, 2.0),)) >>> cursor.execute('SELECT * from test') >>> point = cursor.fetchone()[0] >>> print point 0101000000000000000000F03F0000000000000040 >>> I

Idle (not idle in transaction) connections are not released/closed in PostgreSQL AWS RDS

☆樱花仙子☆ 提交于 2019-12-24 19:05:10
问题 I'm using C3P0 connection pool and PostgreSQL(10.3) in AWS RDS. I did a load test at low TPS (1 TPS) for 2 minutes, after load test finished, the number of connections were not dropped according to the monitoring board in AWS RDS. (See below). Neither did CPU utilization. I'm still new to database, not sure if this is expected? This seems like it's reaching RDS instance's max_connection. I did a select from pg_stat_activity , 99% of connections are idle , and most of the queries are SHOW

How to use passed parameter as table Name in Select query python?

给你一囗甜甜゛ 提交于 2019-12-24 15:51:40
问题 i have the following function which extracts data from table, but i want to pass the table name in function as parameter... def extract_data(table): try: tableName = table conn_string = "host='localhost' dbname='Aspentiment' user='postgres' password='pwd'" conn=psycopg2.connect(conn_string) cursor = conn.cursor() cursor.execute("SELECT aspects_name, sentiments FROM ('%s') " %(tableName)) rows = cursor.fetchall() return rows finally: if conn: conn.close() when i call function as extract_data

PSQL Error Level in Batch For Loop

不打扰是莪最后的温柔 提交于 2019-12-24 15:01:07
问题 I am attempting to run a postgres query from within a batch file. However, I have thus far been unable to detect when the command fails. The following is what I have tried thus far: @FOR /F %%A IN ('PSQL -U userName -d dbName -t -c "SELECT * FROM nonExistantTable" 2^>^&1') DO @( ECHO !ERRORLEVEL! ) I have also tried the following: 1) Adding "CALL" prior to the sql command ( CALL PSQL -U ... ) 2) Adding "-v ON_ERROR_STOP=1" to the sql command, both with and without the "CALL" command ( PSQL -U

pg upgrade saving database definition taking time

假装没事ソ 提交于 2019-12-24 14:27:08
问题 I am in process of a pg_upgrade from 8.4 to 9.3. I am using this technique: http://momjian.us/main/writings/pgsql/pg_upgrade.pdf The upgrade has been running since 250 hours, and it has been on the step saving database definition since 160 hours. This is the current output of strace last few lines: poll([{fd=5, events=POLLIN|. POLLERR}], 1, -1) = 1 ([{fd=5, revents=POLLIN}]) recvfrom(5, "T\0\0\0F \0\2reltoastrelid\0\0\0\4\353\0\n \0\0\0\32\0"..., 16384, 0, NULL, NULL) = 122 (5, "Q\0\0\0

postgresql equivalent to $mysqli->insert_id

跟風遠走 提交于 2019-12-24 14:19:16
问题 Is there an equivalent to $mysqli->insert_id in postgresql 9.3? I am importing into one table, but I need to take the last primary key created in the table and apply it as a foreign key in the second table? Table 1 ----> Table 2 to complete a record. A bit more info: $sql = "INSERT INTO sheet_tbl (site_id, eventdate) VALUES ('$_POST[site_id]','$_POST[eventdate]') returning id"; **Using the sql above, i insert my record, how would I then utilise this in my next SQL insert, If i use returning

FOR loop on PLpgSQL function result

半世苍凉 提交于 2019-12-24 13:12:23
问题 I wrote a PLpgSQL function which should return SETOF products table: CREATE OR REPLACE FUNCTION get_products_by_category (selected_category_id smallint DEFAULT 1) RETURNS SETOF products AS $BODY $BEGIN RETURN QUERY (SELECT * FROM products WHERE CategoryID = selected_category_id); END; $BODY$ LANGUAGE plpgsql VOLATILE NOT LEAKPROOF COST 100 ROWS 1000; And next I want to iterate over results in another function (non-finished view, because I try to add in PgAdmin III and I have errors): DECLARE

why cant see my schema size

久未见 提交于 2019-12-24 08:01:01
问题 If you google for "postgresql table size" you get this nice query. https://wiki.postgresql.org/wiki/Disk_Usage SELECT *, pg_size_pretty(total_bytes) AS total , pg_size_pretty(index_bytes) AS INDEX , pg_size_pretty(toast_bytes) AS toast , pg_size_pretty(table_bytes) AS TABLE FROM ( SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM ( SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME , c.reltuples AS row_estimate , pg_total_relation_size(c.oid) AS total