Tag: postgresql

查找heroku数据库大小最快的方法

在Heroku中找出我的共享数据库的当前大小的最快方法是什么?

如何使用通配符在PostgreSQL中删除多个表

在使用分区时,通常需要一次删除所有分区。 然而 DROP TABLE tablename* 不起作用。 (通配符不被尊重)。 有一个优雅(阅读:容易记得)的方式来删除多个表中的一个命令与通配符?

Python / postgres / psycopg2:获取刚刚插入的行的ID

我正在使用Python和psycopg2来连接到postgres。 当我插入一行… sql_string = "INSERT INTO hundred (name,name_slug,status) VALUES (" sql_string += hundred_name + ", '" + hundred_slug + "', " + status + ");" cursor.execute(sql_string) …我如何获得我刚刚插入的行的ID? 试: hundred = cursor.fetchall() 返回错误,同时使用RETURNING id : sql_string = "INSERT INTO domes_hundred (name,name_slug,status) VALUES (" sql_string += hundred_name + ", '" + hundred_slug + "', " + status […]

使用postgresql存储过程将查询结果存储在variables中

如何使用postgresql存储过程将查询结果存储在variables中 我有一个存储过程 CREATE OR REPLACE FUNCTION test(x numeric) RETURNS character varying AS $BODY$ DECLARE name character varying(255); begin name ='SELECT name FROM test_table where id='||x; if(name='test')then –do somthing else –do the eles part end if; end; return — return my process result here $BODY$ LANGUAGE plpgsql VOLATILE 在上面的过程中,我需要存储 'SELECT name FROM test_table where id='||id; 这个查询将结果返回给variables名称 […]

没有findPsycopg2图片

试图用postgres mac应用程序设置postgres,并且遇到了这个我一直无法解决的错误。 有什么想法吗? ImportError: dlopen(/Users/Craig/pyenv/mysite/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: @executable_path/../lib/libssl.1.0.0.dylib Referenced from: /Applications/Postgres.app/Contents/MacOS/lib/libpq.dylib Reason: image not found

PG ::错误:错误:新编码(UTF8)不兼容

我已经从源安装postgresql-9.2.4 ,现在在rails应用程序执行时: rake db:create命令我得到: $ bin/rake db:create RAILS_ENV="test" PG::Error: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "verticals_test" ENCODING = 'unicode' /home/vagrant/my-project/.gems/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `exec …. bin/rake:16:in `load' bin/rake:16:in `<main>' Couldn't create database […]

PostgreSQL临时表

我需要执行一个查询250万次。 此查询生成一些我需要AVG(column) ,然后使用此AVG从低于平均值的所有值过滤表。 然后我需要将这些过滤的结果插入到表中。 做合理效率的唯一方法似乎是通过为每个query-postmaster python-thread创build一个TEMPORARY TABLE 。 我只是希望这些TEMPORARY TABLE不会永久保存到硬盘上,并且会保留在内存中(RAM),当然,除非它们没有工作内存。 我想知道一个TEMPORARY TABLE是否会引起磁盘写入(这会干扰INSERTS,即整个进程缓慢)

PostgreSQL – 获取列的最大值的行

我正在处理一个包含time_stamp,usr_id,transaction_id和lives_remaining列的logging的Postgres表(称为“lives”)。 我需要一个查询,将给我每个usr_id最近lives_remaining总 有多个用户(不同的usr_id的) time_stamp不是一个唯一的标识符:有时用户事件(在表中按行排列)将以相同的time_stamp出现。 trans_id只有在非常小的时间范围内才是唯一的:随着时间的推移它会重复 remaining_lives(对于给定的用户)可随时间增加和减less 例: TIME_STAMP | lives_remaining | usr_id | TRANS_ID —————————————– 07:00 | 1 | 1 | 1 09:00 | 4 | 2 | 2 10:00 | 2 | 3 | 3 10:00 | 1 | 2 | 4 11:00 | 4 | 1 | 五 11:00 | 3 | 1 […]

如何configurationPostgreSQL接受所有传入的连接

我有一个PostgreSQL的数据库,我想configuration接受所有传入的连接,无论源IP地址。 如何在pg_hba.conf文件中configuration? 我使用的是PostgreSQL 8.4版本。

如何删除PostgreSQL中sorting的固定行数?

我试图将一些旧的MySQL查询移植到PostgreSQL,但是我遇到了这个问题: DELETE FROM logtable ORDER BY timestamp LIMIT 10; PostgreSQL不允许sorting或限制其删除语法,并且表没有主键,所以我不能使用子查询。 此外,我想保留查询删除给定数量或logging的行为,例如,如果表中包含30行,但它们都具有相同的时间戳,我仍然想要删除10,尽pipe它并不重要其中10。 所以; 在PostgreSQL中如何删除固定数量的行? 编辑:没有主键意味着没有log_id列或类似的。 啊,遗留系统的乐趣!