postgresql

Use Django ORM as standalone

Possible Duplicates: Use only some parts of Django? Using only the DB part of Django I want to use the Django ORM as standalone. Despite an hour of searching Google, I'm still left with several questions: Does it require me to set up my Python project with a setting.py, /myApp/ directory, and modules.py file? Can I create a ne...

Is it possible to create a table with a variable name in Postgre SQL?

Using PL/pgSQL or (some other mechanism), is it possible to create a table with a variable name? I would like to create multiple tables named table_1, table_2, table_3, etc... and it would be simpler if I could use a loop to create them, instead of explicitly creating each one. I suspect the answer to this is no, but I would like to co...

Exporting data from spreadsheet to Pgsql database

Hi! I have one huge spreadsheet file (1000+ lines) and one postgreSQL table. I need to compare spreadsheet data with postgresql table data and add fill the blank fields in table with data from spreadsheet and add entries not present in db table. Yes, I can convert (via csv) whole spreadsheet into database table. But, there are unique v...

Find out if user got permission to select/update/... a table/function/... in PostgreSQL

What is the recommended way to figure out if a user got a certain right (e.g. select or execute) on a certain class (e.g. table or function) in PostgreSQL? At the moment I got something like aclcontains( someColumnWithAclitemArray, makeaclitem(userOid,grantorOid,someRight,false)) but it's terrible since I have to check for ev...

how to find what languages are loaded into EnterpriseDB?

How can I find what languages have been loaded into EnterpriseDB(PL/pgsql, SPL, Java)? EnterpriseDB is built on top of PostgreSQL if anyone knows of a way to find the loaded languages on PostgreSQL. It should work the same. ...

Web devs who have made the switch from MySQL, what postgresql features could you now not do without?

I'm contemplating the switch (mainly because of the more permissive license), and tend to hear a lot of Internet murmuring about how much better Postgres is than MySQL, but not many specifics. What do you do in Postgres that make you more productive, or you find elegant? It doesn't have to be fancy, for example some of my favorite thing...

How to build a fully-customizable application (aka database), without lose performance/good-design?

Hi guys, im in the beginning of the complete restyle of an my web application, and i have some doubt about a good database-design that can be reliable, query-performance, and in the same time fully customizable by the users (users wont customize the database structure, but the funcionality of the application). So, my actual situation is...

Can you return multiple result sets using PDO and PostgreSQL?

I would like to group multiple queries into a single function that lives in PostgreSQL. The function will be queried using PDO. The function is: CREATE OR REPLACE FUNCTION "test_multipe_refcursor"() RETURNS SETOF refcursor AS $BODY$ DECLARE parentRC refcursor; childRC refcursor; BEGIN open parentRC FOR SELECT * FROM parent;...

How do I convert an interval into a number of hours with postgres?

Say I have an interval like 4 days 10:00:00 in postgres. How do I convert that to a number of hours (106 in this case?) Is there a function or should I bite the bullet and do something like extract(days, my_interval) * 24 + extract(hours, my_interval) ...

Inferring appropriate database type declarations from strings in Python

I am building some Postgres tables from Python dictionaries where the {'key': 'value'} pairs correspond to column 'key' and field 'value'. These are generated from .dbf files -- I now pipe the contents of the .dbf files into a script that returns a list of dicts like: {'Warngentyp': '', 'Lon': '-81.67170', 'Zwatch_war': '0', 'State':......

Inserting string with single quotes from Java into Postgresql

I'm inserting text from a Java application into a Postgresql database, but it all crashes when a ' char is encountered in the String. I've tried using replaceAll(" ' ", " \\' "); even diffrent variants of it with more \ chars, yet it still puts a single ' in the String without the escape sign. Is there any way of replacing the ' with a...

PostgreSQL return setof record ( virtual table )

Hi, i need a postgres function to return a virtual table ( like in oracle ) with custom content. The table would have 3 columns and an unknown amounts of rows.. i just couldn't find the correct syntax on the internet.. imagine this: CREATE OR REPLACE FUNCTION "public"."storeopeninghours_tostring" (numeric) RETURNS setof record AS DEC...

Outer join with conditions?

I'm trying to look up two pieces of metadata (volume and issue) on items which may have either a volume, issue, or both. The metadata is stored in a table with item ID, key (metadata field ID) and value. This does work, but it seems overly complex and repetitive: select volume.text_value as volume_value, issue.text_value as issue_valu...

Speed of IN keyword in MySQL/PostgreSQL

I've heard lots of people saying that the IN keyword in most relational databases is slow. How true is this? An example query would be this, off the top of my head: SELECT * FROM someTable WHERE someColumn IN (value1, value2, value3) I've heard that is much slower than doing this: SELECT * FROM someTable WHERE someColumn = value1 O...

How can I determine if one PGArray is included in another using SQLAlchemy sessions?

I have an SqlAlchemy table like so: table = sql.Table('treeItems', META, sql.Column('id', sql.Integer(), primary_key=True), sql.Column('type', sql.String, nullable=False), sql.Column('parentId', sql.Integer, sql.ForeignKey('treeItems.id')), sql.Column('lineage', PGArray(sql.Integer)), sql.Column('depth', sql.Integer)...

Why do I get an error when I try to execute a query with parameters in postgreSQL?

The db is PostgreSQL. When I try to execute a query with parameters, such as this one cursor.execute(""" SELECT u.username, up.description, ts_rank_cd(to_tsvector(coalesce(username,'')|| coalesce(description,'')) , to_tsquery('%s')) as rank FROM auth_user u INNER JOIN pm_core_userprofile up on u.id = up.user_id ...

How can I speed up update/replace operations in PostgreSQL?

We have a rather specific application that uses PostgreSQL 8.3 as a storage backend (using Python and psycopg2). The operations we perform to the important tables are in the majority of cases inserts or updates (rarely deletes or selects). For sanity reasons we have created our own Data Mapper-like layer that works reasonably well, but...

Making PostgreSQL a little more error tolerant?

This is sort of a general question that has come up in several contexts, the example below is representative but not exhaustive. I am interested in any ways of learning to work with Postgres on imperfect (but close enough) data sources. The specific case -- I am using Postgres with PostGIS for working with government data published in...

Can I restore just one schema from a pg_dump of the entire database?

I have backups of my postgres database - the entire database instance in a single nightly backup. Is it possible to restore just one of the database from within that backup? Or if I want to access individual databases (for migration or restoring), do I need to change my database backup scheme to do individual dumps? ...

Postgres and Indexes on Foreign Keys and Primary Keys

Does Postgres automatically put indexes on Foreign Keys and Primary Keys? How can I tell? Is there a command that will return all indexes on a table? ...