postgresql-9.2

Get functions DDL command

做~自己de王妃 提交于 2020-01-06 23:49:06
问题 I need to get DDL of every function in my db for versioning purpose. Here is the query, but it works only for functions in public schema. When I'm trying to use it to get create of functions which exists in public and match schema I get error that subquery returns too many rows. By checking all values from pg_proc using this query: select * from pg_proc where proname = 'match_group_1_3_2'; Only values that changes is pronamespace: How to distinguish both (or more) function? How to distinguish

combine date and integer in ARRAY

孤街醉人 提交于 2020-01-05 05:54:16
问题 How to select array_agg(ARRAY[f1_date,ARRAY[f2_int,f3_decimal]]) ? There is an error about combining date and integer in ARRAY. upd: added picture explaining where and how I plan to use array. The issue is db size. After transforming 3 colunms to multidimensional array I can save plenty of space. It will be 4M rows instead of 200M. Each row will have array with maximum 500 elements inside. 回答1: Arrays in Postgres share the same base element across all dimensions. Array of anonymous records

Insert using a function that returns two values per row

前提是你 提交于 2020-01-04 04:19:26
问题 This function: CREATE OR REPLACE FUNCTION fn_test1() RETURNS SETOF date AS $BODY$ declare i int; begin i:=0; while i<5 loop return next '2001-01-02'::date; i:=i+1; end loop; end $BODY$ LANGUAGE plpgsql VOLATILE COST 100 ROWS 1000; This table: CREATE TABLE teste1 ( teste1_id serial NOT NULL, num integer, fn_date date) An INSERT like this works just fine (inserting 5 rows): Insert into teste1(num,fn_date) select 1, fn_test1(); But if I want to have a function that returns two dates in a row,

How can I achieve the same Postgres collation behavior in Linux as that in Mac OS?

微笑、不失礼 提交于 2020-01-02 03:15:19
问题 When switching between Mac OS (development) to Linux (production server), the collation for Postgres changes since collation in Postgres is dependent on the underlying operating system config. How can I achieve the same Postgres collation behavior in Linux as that which I have in Mac OS? I am running Postgres 9.2 回答1: The locales on OS X are sufficiently broken and the ones on Linux (glibc) are sufficiently not, so that you are going to have difficulties sorting this out successfully. The

Loose index scan in Postgres on more than one field?

Deadly 提交于 2020-01-02 02:01:07
问题 I have several large tables in Postgres 9.2 (millions of rows) where I need to generate a unique code based on the combination of two fields, 'source' (varchar) and 'id' (int). I can do this by generating row_numbers over the result of: SELECT source,id FROM tablename GROUP BY source,id but the results can take a while to process. It has been recommended that if the fields are indexed, and there are a proportionally small number of index values (which is my case), that a loose index scan may

Test script for transaction concurrency for postgresql

喜夏-厌秋 提交于 2020-01-01 19:04:27
问题 I would like to test some variants of transaction concurrency in PostgreSQL and for that I need a script which would force two transaction to start at exactly the same time. Something that does not requires manual intervention ;) Any ideas? 回答1: You can homebrew this by taking a LOCK on a table, setting up your transactions, then releasing the lock by rolling back the transaction that got the lock. See this prior answer and its links for details on this approach. While I demonstrated it using

How to alter owner of a function in postgres

冷暖自知 提交于 2020-01-01 05:39:08
问题 I am writing a script to alter all functions of postgres(changing owner of each function). I am able to list down all the function names using postgres query but not able to list parameters for each of those functions. My problem will be resolved if I get solution for any of the below mentioned problems: Is there any way to list down parameters' data type in each of the function. Do we have any approach to alter functions where instead of passing parameter type can I send some wild card. For

PostgreSQL create index on cast from string to date

浪尽此生 提交于 2020-01-01 04:22:23
问题 I'm trying to create an index on the cast of a varchar column to date. I'm doing something like this: CREATE INDEX date_index ON table_name (CAST(varchar_column AS DATE)); I'm getting the error: functions in index expression must be marked IMMUTABLE But I don't get why, the cast to date doesn't depends on the timezone or something like that (which makes a cast to timestamp with time zone give this error). Any help? 回答1: Your first error was to store a date as a varchar column. You should not

Entity Framework 5.0 PostgreSQL (Npgsql) default connection factory

折月煮酒 提交于 2020-01-01 02:43:09
问题 I'm trying to get EF 5.0 code first working with PostgreSQL (Npgsql provider). I have Npgsql 2.0.12.1 installed via NuGet (referenced assembly is 2.0.12.0 though). I have Npgsql declared in app.config (both default connection factory and provider factory): <entityFramework> <defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" /> </entityFramework> <system.data> <DbProviderFactories> <add name="Npgsql Data Provider"

Select from a table variable

无人久伴 提交于 2019-12-28 04:28:06
问题 I am trying to save the result of a SELECT query, pass it, and reuse it in another PL/pgSQL function: DECLARE table_holder my_table; --the type of table_holder is my_table; result text; BEGIN SELECT * INTO table_holder FROM table_holder ; result = another_function(table_holder); return result; END The code for another_function(table_holder my_table) , respectively: BEGIN RETURN QUERY SELECT col FROM table_holder where id = 1; END Is it possible to run a SELECT query on a variable? If not, is