postgresql-9.0

ALTER TABLE to add ON DELETE CASCADE statement

落爺英雄遲暮 提交于 2019-12-11 18:48:45
问题 I want to do the following in PostgreSQL (using Hibernate): ALTER TABLE fruits ADD CONSTRAINTS id ON DELETE CASCADE; Obviously, my code above is not working, so I am looking for the correct statement. If I can't do that, then how about the following: I have a bunch of data in my table fruits . The id field in fruits is used as a foreign key by table grapes . I need to delete a specific row in fruits and I want the deletion to cascade to grapes and delete all entries in grapes that has the

ILIKE Match Word Boundaries PostgreSQL 9

若如初见. 提交于 2019-12-11 09:42:54
问题 When using the LIKE/ILIKE operator in PostgreSQL 9 is it possible to match word boundaries without having to use full blown ~ operator regular expressions? For example SELECT 'Super fast training' ILIKE '%train\M%' as match; Where \M is the boundary at the end of a word and match returns false Thanks, Mark 回答1: you can do it with following trick: SELECT ' ' || 'Super fast training' ILIKE '%train %' but I don't hink so it is a good idea. You can use regular expression or PostgreSQL fulltext

Is it possible to use a stable function in an index in Postgres?

故事扮演 提交于 2019-12-10 18:29:35
问题 I've been working on a project at work and have come to the realization that I must invoke a function in several of the queries' WHERE clauses. The performance isn't terrible exactly, but I would love to improve it. So I looked at the docs for indexes which mentioned that: An index field can be an expression computed from the values of one or more columns of the table row. Awesome. So I tried creating an index: CREATE INDEX idx_foo ON foo_table (stable_function(foo_column)); And received an

DATE_FORMAT in postgresql

寵の児 提交于 2019-12-09 15:46:54
问题 I'm working in postgresql and I need to convert the date format in query itself, in mysql there is option called DATE_FORMAT and I can use a query like this: Select DATE_FORMAT(date_time, '%b %e, %Y, %T') from table_name is there any option in postgresql? Please let me know if any? 回答1: If I modify your Select DATE_FORMAT(date_time, '%b %e, %Y, %T') from table_name to Select DATE_FORMAT(now(), '%b %e, %Y, %T') it will return Aug 21, 2012, 16:51:30 . You can do the same thing in Postgresql:

Restrict foreign key relationship to rows of related subtypes

不想你离开。 提交于 2019-12-04 05:11:11
问题 Overview: I am trying to represent several types of entities in a database, which have a number of basic fields in common, and then each has some additional fields that are not shared with the other types of entities. Workflow would frequently involve listing the entities together, so I have decided to have a table with their common fields, and then each entity will have its own table with its additional fields. To implement: There is a common field, “status”, which all entities have; however

Is there any difference between integer and bit(n) data types for a bitmask?

人走茶凉 提交于 2019-12-03 23:28:34
I am working with a table in a PostgreSQL database that has several boolean columns that determine some state (e.g. published , visible , etc.). I want to make a single status column that will store all these values as well as possible new ones in a form of a bitmask. Is there any difference between integer and bit(n) in this case? This is going to be a rather big table, because it stores objects that users create via a web-interface. So I think I will have to use (partial) indexes for this column. Erwin Brandstetter If you only have a few variables I would consider keeping separate boolean

postgresql error PANIC: could not locate a valid checkpoint record

£可爱£侵袭症+ 提交于 2019-12-03 02:11:27
问题 When I load up the postgres server (v9.0.1) i get a panic that prevents it from starting: PANIC: could not locate a valid checkpoint record How can I fix this? 回答1: It's looking for a checkpoint record in the transaction log that probably doesn't exist or is corrupted. You can determine if this is the case by running: # Postgres < 10.0 pg_resetxlog DATADIR # Postgres >= 10.0 pg_resetwal DATADIR If the transaction log is corrupt, you'll see a message like: The database server was not shut down

postgresql error PANIC: could not locate a valid checkpoint record

大城市里の小女人 提交于 2019-12-02 16:07:41
When I load up the postgres server (v9.0.1) i get a panic that prevents it from starting: PANIC: could not locate a valid checkpoint record How can I fix this? Erwin Brandstetter It's looking for a checkpoint record in the transaction log that probably doesn't exist or is corrupted. You can determine if this is the case by running: # Postgres < 10.0 pg_resetxlog DATADIR # Postgres >= 10.0 pg_resetwal DATADIR If the transaction log is corrupt, you'll see a message like: The database server was not shut down cleanly. Resetting the transaction log might cause data to be lost. If you want to

dblink can't update a table on the same database in an after UPDATE trigger

这一生的挚爱 提交于 2019-12-02 14:36:10
问题 I am working on a database replicated using slony and trying to create a trigger which will be triggered after an INSERT operation on a table. In this trigger I am trying to update another table of THE SAME database using dblink. But I am getting an error saying that the value I just inserted in the first table does not exist when I am trying to update the second table. I am using dblink because if I update the second table with a regular UPDATE statement, slony synchronization is not

dblink can't update a table on the same database in an after UPDATE trigger

主宰稳场 提交于 2019-12-02 10:14:29
I am working on a database replicated using slony and trying to create a trigger which will be triggered after an INSERT operation on a table. In this trigger I am trying to update another table of THE SAME database using dblink. But I am getting an error saying that the value I just inserted in the first table does not exist when I am trying to update the second table. I am using dblink because if I update the second table with a regular UPDATE statement, slony synchronization is not triggered. First table: CREATE TABLE "COFFRETS" ( "NUM_SERIE" character varying NOT NULL, "DATE_CREATION"