postgresql-9.2

How to make a select with array contains value clause in psql

徘徊边缘 提交于 2019-11-27 06:31:46
I have column arr which is of type array . I need to get rows, where arr column contains value s This query: SELECT * FROM table WHERE arr @> ARRAY['s'] gives the error: ERROR: operator does not exist: character varying[] @> text[] Why does it not work? p.s. I know about any() operator, but why doesn't @> work? Wojtas Try SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[] Note that this may also work: SELECT * FROM table WHERE s=ANY(array) SELECT * FROM table WHERE arr && '{s}'::text[]; Compare two arrays for containment. 来源: https://stackoverflow.com/questions/16606357/how-to-make-a

How to create sequence if not exists

白昼怎懂夜的黑 提交于 2019-11-27 03:07:58
问题 I tried to use code from Check if sequence exists in Postgres (plpgsql). To create sequence if it does not exists. Running this code two times causes an exception: sequence ... already exists. How to create sequence only if it does not exist? If the sequence does not exist, no message should be written and no error should occur so I cannot use the stored procedure in the other answer to this question since it writes message to log file every time if sequence exists. do $$ begin SET search

How do I start enterpiseDB PostgreSQL on Mac OSX 10.6.8?

柔情痞子 提交于 2019-11-27 02:28:43
问题 Mac OSX 10.6.8 The postgres website says postgres 9.2+ is compatible with Mac OSX 10.6+, so I downloaded the 9.2.4 version of the installer for Mac OSX here: http://www.enterprisedb.com/products-services-training/pgdownload I accepted all the defaults, so postgres was installed in the directory: /Library/PostgreSQL/9.2 (If you are installing postgres for rails development, in order to install the pg gem you need to add to your PATH: http://excid3.com/blog/installing-postgresql-and-pg-gem-on

Importing .csv with timestamp column (dd.mm.yyyy hh.mm.ss) using psql \copy

穿精又带淫゛_ 提交于 2019-11-26 21:36:30
问题 I'm trying to import data from a .csv file into a postgresql 9.2 database using the psql \COPY command (not the SQL COPY). The input .csv file contains a column with a timestamp in the dd.mm.yyyy hh.mm.ss format. I've set the database datestyle to DMY using. set datestyle 'ISO,DMY' Unfortunately, when I run the \COPY command: \COPY gc_test.trace(numpoint,easting,northing,altitude,numsats,pdop,timestamp_mes,duration,ttype,h_error,v_error) FROM 'C:\data.csv' WITH DELIMITER ';' CSV HEADER

Permission denied for relation

大憨熊 提交于 2019-11-26 19:14:29
I tried to run simple sql command: select * from site_adzone; and I got this error ERROR: permission denied for relation site_adzone What could be the problem here? I tried also to do select for other tables and got same issue. I also tried to do this: GRANT ALL PRIVILEGES ON DATABASE jerry to tom; but I got this response from console WARNING: no privileges were granted for "jerry" Do you have some idea what can be wrong? GRANT on the database is not what you need. Grant on the tables directly. Granting privileges on the database mostly is used to grant or revoke connect privileges. This

Return SETOF rows from PostgreSQL function

♀尐吖头ヾ 提交于 2019-11-26 17:02:38
问题 I have a situation where I want to return the join between two views. and that's a lot of columns. It was pretty easy in sql server. But in PostgreSQL when I do the join. I get the error "a column definition list is required". Is there any way I can bypass this, I don't want to provide the definitions of returning columns. CREATE OR REPLACE FUNCTION functionA(username character varying DEFAULT ''::character varying, databaseobject character varying DEFAULT ''::character varying) RETURNS SETOF

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

旧城冷巷雨未停 提交于 2019-11-26 15:26:40
I am trying to open a program for the first time on Windows XP Pro that uses PostgreSQL 9. I'm getting an error message that says : A problem was encountered while trying to log into or create the production database. Details: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified In my ODBC manager, I have a list of User DSN's and System DSN's. I tried installing a postgres odbc driver to see if that would help, but it didn't. There is a connect.dat file in the program file with a line saying "OLE DB Provider = MSDASQL". Changing this entry alters the

Find duplicate rows with PostgreSQL

蓝咒 提交于 2019-11-26 15:17:43
问题 We have a table of photos with the following columns: id, merchant_id, url this table contains duplicate values for the combination merchant_id, url . so it's possible that one row appears more several times. 234 some_merchant http://www.some-image-url.com/abscde1213 235 some_merchant http://www.some-image-url.com/abscde1213 236 some_merchant http://www.some-image-url.com/abscde1213 What is the best way to delete those duplications? (I use PostgreSQL 9.2 and Rails 3.) 回答1: Here is my take on

What is the maximum number of columns in a PostgreSQL select query

一曲冷凌霜 提交于 2019-11-26 13:46:20
Do you know what the maximum number of columns that can be queried in Postgresql? I need to know this before I start my project. According to About PostgreSQL it's "250 - 1600 depending on column types". See "Limits". The column types affect it because in PostgreSQL rows may be at most 8kb (one page) wide, they cannot span pages. Big values in columns are OK because TOAST handles that, but there's a limit to how many columns you can fit in that depends on how wide the un-TOASTed data types used are. (Strictly this refers to columns that can be stored in on-disk rows; queries might be able to

How to make a select with array contains value clause in psql

拜拜、爱过 提交于 2019-11-26 12:01:54
问题 I have column arr which is of type array . I need to get rows, where arr column contains value s This query: SELECT * FROM table WHERE arr @> ARRAY[\'s\'] gives the error: ERROR: operator does not exist: character varying[] @> text[] Why does it not work? p.s. I know about any() operator, but why doesn\'t @> work? 回答1: Try SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[] 回答2: Note that this may also work: SELECT * FROM table WHERE s=ANY(array) 回答3: SELECT * FROM table WHERE arr && '{s}'