postgresql-9.1

PostgreSQL next value of the sequences?

我是研究僧i 提交于 2019-11-27 13:55:20
I am using PostgreSQL for my Codeigniter website. I am using grocery crud for add, edit and delete operations. While doing an edit or add, I want to rename an uploaded file dynamically based on the id of the content. I am able to do this using grocery crud's callback_after_upload function. I want a next id of the content while adding a new content. I tried to use nextval() function, but sequence gets incremented with it. How can get the last value of the sequence without using nextval() function? Or is there a simple way I can do this? Erwin Brandstetter RETURNING In modern-day PostgreSQL (8.2

Error when creating unaccent extension on PostgreSQL

那年仲夏 提交于 2019-11-27 13:27:06
I am trying to configure PostgreSQL to use fulltext search in my rails app as mentioned in this Railscast . I am using a fresh Ubuntu 12.04 server running PostgreSQL 9.1.5 installed using apt-get with the ppa:pitti/postgresql with precise . I get the following error when trying to run the migration and when I try the same command in the psql console with the peer postgres user: postgres=# CREATE EXTENSION unaccent; ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/unaccent.control": No such file or directory In my local box running Ubuntu 10.04 desktop I use the

Test for null in function with varying parameters

拥有回忆 提交于 2019-11-27 12:57:12
I have a Postgres function: create function myfunction(integer, text, text, text, text, text, text) RETURNS table(id int, match text, score int, nr int, nr_extra character varying, info character varying, postcode character varying, street character varying, place character varying, country character varying, the_geom geometry) AS $$ BEGIN return query (select a.id, 'address' as match, 1 as score, a.ad_nr, a.ad_nr_extra,a.ad_info,a.ad_postcode, s.name as street, p.name place , c.name country, a.wkb_geometry as wkb_geometry from "Addresses" a left join "Streets" s on a.street_id = s.id left

Determining the OID of a table in Postgres 9.1?

本小妞迷上赌 提交于 2019-11-27 12:47:16
问题 Does anyone know how to find the OID of a table in Postgres 9.1? I am writing an update script that needs to test for the existence of a column in a table before it tries to create the column. This is to prevent run of the script after the first from erroring out. 回答1: The postgres catalog table pg_class is what you should look at. There should be one row per table, with the table name in the column relname , and the oid in the hidden column oid . The catalog tables are in the postgres

How to add column if not exists on PostgreSQL?

浪子不回头ぞ 提交于 2019-11-27 11:09:37
Question is simple. How to add column x to table y , but only when x column doesn't exist ? I found only solution here how to check if column exists. SELECT column_name FROM information_schema.columns WHERE table_name='x' and column_name='y'; Here's a short-and-sweet version using the "DO" statement: DO $$ BEGIN BEGIN ALTER TABLE <table_name> ADD COLUMN <column_name> <column_type>; EXCEPTION WHEN duplicate_column THEN RAISE NOTICE 'column <column_name> already exists in <table_name>.'; END; END; $$ You can't pass these as parameters, you'll need to do variable substitution in the string on the

How to create a new database with the hstore extension already installed?

微笑、不失礼 提交于 2019-11-27 10:39:27
Recently I went into trouble trying to use hstore with Django. I installed hstore this way: $ sudo -u postgres psql postgres=# CREATE EXTENSION hstore; WARNING: => is deprecated as an operator name DETAIL: This name may be disallowed altogether in future versions of PostgreSQL. CREATE EXTENSION postgres=# \dx List of installed extensions Name | Version | Schema | Description ---------+---------+------------+-------------------------------------------------- hstore | 1.0 | public | data type for storing sets of (key, value) pairs plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language (2 rows

Change type of varchar field to integer: “cannot be cast automatically to type integer”

三世轮回 提交于 2019-11-27 10:12:17
I have a small table and a certain field contains the type " character varying ". I'm trying to change it to " Integer " but it gives an error that casting is not possible. Is there a way around this or should I just create another table and bring the records into it using a query. The field contains only integer values. Craig Ringer There is no implicit (automatic) cast from text or varchar to integer (i.e. you cannot pass a varchar to a function expecting integer or assign a varchar field to an integer one), so you must specify an explicit cast using ALTER TABLE ... ALTER COLUMN ... TYPE ...

How to exit from PostgreSQL command line utility: psql

こ雲淡風輕ζ 提交于 2019-11-27 09:55:31
What command or short key can I use to exit the PostgreSQL command line utility psql ? Type \q and then press ENTER to quit psql . UPDATE: 19-OCT-2018 As of PostgreSQL 11 , the keywords " quit " and " exit " in the PostgreSQL command-line interface have been included to help make it easier to leave the command-line tool. My usual key sequence is: quit() quit exit() exit q q() !q ^C help Alt + Tab google.com Quit PSQL \q I think veterans of the psql command line usually shorten that to just: \q Kaarel Ctrl + D is what I usually use to exit psql console. Try: Ctrl + Z - this sends the TSTP

Query a parameter (postgresql.conf setting) like “max_connections”

橙三吉。 提交于 2019-11-27 09:16:59
问题 Does anyone know if it's even possible (and how, if yes) to query a database server setting in PostgreSQL (9.1)? I need to check the max_connections (maximum number of open db connections) setting. 回答1: Can be as simple as: SHOW max_connections; This returns the currently effective setting. Be aware that it can differ from the setting in postgresql.conf as there are a couple of ways to set run-time parameters in PostgreSQL. To reset the "original" setting from postgresql.conf in your current

Failed to find conversion function from unknown to text

久未见 提交于 2019-11-27 06:33:58
问题 In one of my select statements I've got the following error: ERROR: failed to find conversion function from unknown to text ********** Error ********** ERROR: failed to find conversion function from unknown to text SQL state: XX000 This was easy to fix using cast , but I do not fully understand why it happened. I will ilustrate my confusion with two simple statements. This one is OK: select 'text' union all select 'text'; This will return error: with t as (select 'text') select * from t union