postgresql-9.1

Why does PostgreSQL treat my query differently in a function?

a 夏天 提交于 2019-11-30 18:56:14
问题 I have a very simple query that is not much more complicated than: select * from table_name where id = 1234 ...it takes less than 50 milliseconds to run. Took that query and put it into a function: CREATE OR REPLACE FUNCTION pie(id_param integer) RETURNS SETOF record AS $BODY$ BEGIN RETURN QUERY SELECT * FROM table_name where id = id_param; END $BODY$ LANGUAGE plpgsql STABLE; This function when executed select * from pie(123); takes 22 seconds. If I hard code an integer in place of id_param,

Postgresql batch insert or ignore

被刻印的时光 ゝ 提交于 2019-11-30 14:43:49
I have the responsibility of switching our code from sqlite to postgres. One of the queries I am having trouble with is copied below. INSERT INTO group_phones(group_id, phone_name) SELECT g.id, p.name FROM phones AS p, groups as g WHERE g.id IN ($add_groups) AND p.name IN ($phones); The problem arises when there is a duplicate record. In this table the combination of both values must be unique. I have used a few plpgsql functions in other places to do update-or-insert operations, but in this case I can do several inserts at once. I am not sure how to write a stored routine for this. Thanks for

JPA Hibernate Call Postgres Function Void Return MappingException:

一曲冷凌霜 提交于 2019-11-30 12:06:54
I have a problem where I am getting an: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111 when trying to call a postgres function using JPA create native query. I created an EJB timer in a startup singleton to run a Postgres function every 6 hours. The function returns void and checks for expired records, deletes them, and updates some statuses. It takes no arguments and it returns void. The postgres function runs perfectly if I call it using PgAdmin query tool (select function();) and returns void. When I deploy the app on Glassfish 3.1.1 I get an exception and a failure

No password prompt for postgresql superuser

僤鯓⒐⒋嵵緔 提交于 2019-11-30 11:42:28
After I installed PostgreSQL 9.1 on Ubuntu 12.04 I set the password for the "postgres" superuser account. I want all users to have to enter their password when loging in. This is why I configured pg_hba.conf like so: #Database administrative login by Unix domain socket local all postgres md5 # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all md5 I restarted postgresql after making those changes. When I do this psql -U testuser I get asked for a password, but when I log in with the "postgres" account like so psql -U postgres I get no password

Hibernate startup very slow

亡梦爱人 提交于 2019-11-30 11:16:40
For some reason, the startup of my hibernate application is unbarrably slow. (up to 2 min) I have been thinking that the c3p0 configuration is plain wrong ( related question ) but studying the logs shows, that there is no activity just after the connection to the server is established. Also, using the built-in polling capabilities of Hibernate shows the same result. Here is a snippet from the logs: 20:06:51,248 DEBUG BasicResourcePool:422 - decremented pending_acquires: 0 20:06:51,248 DEBUG BasicResourcePool:1644 - trace com.mchange.v2.resourcepool.BasicResourcePool@1acaf0ed [managed: 3,

How do I convert an integer to string as part of a PostgreSQL query?

两盒软妹~` 提交于 2019-11-30 10:42:45
问题 How do I convert an integer to string as part of a PostgreSQL query? So, for example, I need: SELECT * FROM table WHERE <some integer> = 'string of numbers' where <some integer> can be anywhere from 1 to 15 digits long. 回答1: Because the number can be up to 15 digits, you'll meed to cast to an 64 bit (8-byte) integer. Try this: SELECT * FROM table WHERE myint = mytext::int8 The :: cast operator is historical but convenient. Postgres also conforms to the SQL standard syntax myint = cast (

“use database_name” command in PostgreSQL

穿精又带淫゛_ 提交于 2019-11-30 10:13:56
问题 I am beginner to PostgreSQL. I want to connect to another database from the query editor of Postgres - like the USE command of MySQL or MS SQL Server. I found \c databasename by searching the Internet, but its runs only on psql. When I try it from the PostgreSQL query editor I get a syntax error. I have to change the database by pgscripting. Does anyone know how to do it? 回答1: When you get a connection to PostgreSQL it is always to a particular database. To access a different database, you

Drop column doesn't remove column references entirely - postgresql

邮差的信 提交于 2019-11-30 10:01:36
问题 I have a table that contained 1600 columns and would like to add more fields in that but as per the database rule the more fields not allowed to be created because the higher limit reached. So I decided to drop few unwanted fields from the table and I did it. Again I tried to add few fields in that table but it's raise the same error that 1600 columns are there you can't add more. I gone through other tables of postgresql " pg_attribute " and all those fields are there and having delete

Aggregate hstore column in PostreSQL

守給你的承諾、 提交于 2019-11-30 09:21:19
I have a table like this: Table "public.statistics" id | integer | not null default nextval('statistics_id_seq'::regclass) goals | hstore | items: |id |goals | |30059 |"3"=>"123" | |27333 |"3"=>"200", "5"=>"10" | What I need to do for aggregate all values by key in hash? I want to get result like this: select sum(goals) from statistics return |goals | |"3"=>"323", "5"=>"10" | Building on Laurence's answer, here's a pure SQL way to aggregate the summed key/value pairs into a new hstore using array_agg and the hstore(text[], text[]) constructor. http://sqlfiddle.com/#!1/9f1fb/17 SELECT hstore

FATAL: password authentication failed for user “postgres”

北城以北 提交于 2019-11-30 07:08:19
getting this error message in ubuntu. in pg_hba.conf file, I tried using 'ident','peer','trust','md5' in different times.but no go. please help. in your pg_hba.conf # IPv4 local connections: # TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 127.0.0.1/32 trust if it does not work then try with host all all your_ip/32 trust then restart your data base it will work fine If the username and password are correct then md5 is the correct value. Make sure you restart the database process or at least have it reload the configuration after modifying pg_hba.conf . It might be came from malicious