postgresql-9.2

Check statistics targets in PostgreSQL

我是研究僧i 提交于 2019-11-29 05:40:10
I have searched but been unable to find any simple, straight forward answer to this. How do I check the current statistics targets used by ANALYZE? The setting for the statistics target is stored per column in the catalog table pg_attribute . You can set it like this: ALTER TABLE myschama.mytable ALTER mycolumn SET STATISTICS 127; And check it like this: SELECT attstattarget FROM pg_attribute WHERE attrelid = 'myschama.mytable'::regclass AND attname = 'mycolumn'; Or you just look at the creation script in the object browser of pgAdmin, where it is appended if the value is distinct from the

Changing a column from string to string array in postgresql

吃可爱长大的小学妹 提交于 2019-11-29 03:35:49
The following is a snippet of a table called "containers". Column | Type | Modifiers --------------------+-----------------------------+--------------------------------- id | uuid | not null name | character varying(255) | products | character varying | default '{}'::character varying How can I alter the products column to "character varying[]" and the corresponding modifiers to default '{}'::character varying[] ? Essentially, I want to convert a string to a string array. Note the products column has no limit on the number of characters. alter table "containers" alter "products" type character

How do I get my rails app to use my postgresql db?

£可爱£侵袭症+ 提交于 2019-11-29 02:46:58
I installed prostgres to use with my rails4 app, and I am able to connect to the database server and create databases. Then I made the necessary changes to my Gemfile and config/database.yml to use postgres. Then I created a new app, and in the app I created a User model: $ rails generate model User name:string email:string invoke active_record create db/migrate/20130806145935_create_users.rb create app/models/user.rb invoke rspec create spec/models/user_spec.rb And then I did: $ bundle exec rake db:migrate == CreateUsers: migrating ==================================================== --

Get all procedural , user defined functions

孤者浪人 提交于 2019-11-29 01:39:16
问题 How to get list of all user defined functions via SQL query ? I find this code here SELECT p.proname, p.pronargs, t.typname FROM pg_proc p, pg_language l, pg_type t WHERE p.prolang = l.oid and p.prorettype = t.oid and l.lanname = 'c' ORDER BY proname; but this gets C-functions How to get user defined, procedural language functions, writen for example in plpgsql language? 回答1: Consider: select pp.proname, pl.lanname, pn.nspname, pg_get_functiondef(pp.oid) from pg_proc pp inner join pg

How to run an ad-hoc script in PostgreSQL?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 19:44:30
问题 I'm trying to run this in PostgreSQL 9.2: RAISE NOTICE 'hello, world!'; And the server says: Error : ERROR: syntax error at or near "RAISE" LINE 1: RAISE NOTICE 'hello, world!' ^ Why? 回答1: Use an anonymous code block: DO language plpgsql $$ BEGIN RAISE NOTICE 'hello, world!'; END $$; Variables are referenced using % : RAISE NOTICE '%', variable_name; 回答2: raise is PL/pgSQL only. http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html create or replace function r(error

PostgreSql INSERT FROM SELECT RETURNING ID

旧城冷巷雨未停 提交于 2019-11-28 19:31:46
问题 In PostgreSql 9.2.4 I have two tables: user (id, login, password, name) and dealer (id, user_id) . And I want to insert into both tables returning id of created dealer. Currently I'm doing it with two queries: WITH rows AS ( INSERT INTO "user" (login, password, name) VALUES ('dealer1', 'jygbjybk', 'Dealer 1') RETURNING id ) INSERT INTO dealer (user_id) SELECT id FROM rows; SELECT currval('dealer_id_seq'); But can I implement this with a single INSERT query using RETURNING statement? 回答1: You

How to change the template database collection coding

一曲冷凌霜 提交于 2019-11-28 18:41:10
I want build new postgreSQL database by: CREATE DATABASE newdb WITH OWNER = postgres ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'zh_CN.UTF-8' CONNECTION LIMIT = -1; and the error is: ERROR: new collation (zh_CN.UTF-8) is incompatible with the collation of the template database (en_US.UTF8) HINT: Use the same collation as in the template database, or use template0 as template. How to change the template database collection? Tomas Greif From PostgreSQL documentation: Another common reason for copying template0 instead of template1 is that new encoding and locale settings can be

Connecting PostgreSQL 9.2.1 with Hibernate

安稳与你 提交于 2019-11-28 15:55:32
问题 I have a blank Spring MVC project, and I've installed Hibernate and the PostgreSQL drivers using Maven. I'm running short on complete tutorials that show how to connect PostgreSQL with Hibernate. Any help here? 回答1: This is a hibernate.cfg.xml for posgresql and it will help you with basic hibernate configurations for posgresql. <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate

PostgreSQL query to list all table names?

时光毁灭记忆、已成空白 提交于 2019-11-28 15:31:52
问题 Is there any query available to list all tables in my Postgres DB. I tried out one query like: SELECT table_name FROM information_schema.tables WHERE table_schema='public' But this query returns views also. How can i get only table names only, not views? 回答1: What bout this query (based on the description from manual)? SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'; 回答2: If you want list of database SELECT datname FROM pg_database

Postgresql 9.2 pg_dump version mismatch

不问归期 提交于 2019-11-28 15:29:40
I am trying to dump a Postgresql database using the pg_dump tool. $ pg_dump books > books.out How ever i am getting this error. pg_dump: server version: 9.2.1; pg_dump version: 9.1.6 pg_dump: aborting because of server version mismatch The --ignore-version option is now deprecated and really would not be a a solution to my issue even if it had worked. How can I upgrade pg_dump to resolve this issue? francs You can either install PostgreSQL 9.2.1 in the pg_dump client machine or just copy the $PGHOME from the PostgreSQL server machine to the client machine. Note that there is no need to initdb