Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 6219

All versions of PostgreSQL. Add an additional version-specific tag like [postgresql-13] if that context is relevant.

10 votes

How do I determine if a column is defined as a serial data type instead of an integer based ...

Let me add to efesar's answer that the documentation states the following: The data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating u …
András Váczi's user avatar
2 votes

Can Postgres raise warnings if joins are inconsistant with foreign keys?

It is up to the developer/DBA to write sensible joins, in this regard PostgreSQL is just a slave that does what its master commands. …
András Váczi's user avatar
1 vote
Accepted

Improve SQL query

It looks like raising the work_mem by some MBs (say 30) would speed things up significantly. You could also remove the ORDER BY clause from the aggregation CTE. Similarly, the GROUP BY in the subquer …
András Váczi's user avatar
2 votes
Accepted

How to specify the primary key number space for a postgres table?

If you want to happen it automatically (I mean, without the application doing that), you have to create a sequence: CREATE SEQUENCE some_table_pk_seq START 50; Then change the column to use this as …
András Váczi's user avatar
1 vote

Help with query statement

You can self join the table so that on the left there are the hosts for month 1, on the right for month 9: SELECT host, risk, plugin_id, month, year FROM your_table t1 JOIN your_table t2 ON t1.mo …
András Váczi's user avatar
2 votes

Creating a table if it doesn't exist (old versions of PostgreSQL)

The actual solution very much depends on your exact situation. If you can use a pl/pgsql function, you can check first for the existence of the table: IF NOT EXISTS (SELECT 1 FROM pg_class WHERE rel …
András Váczi's user avatar
2 votes
Accepted

Removing records from database periodically that surpass timeline

Second, you have to keep your table tidy by vacuuming it regularly - if you have a relatively recent PostgreSQL version, there are chances that the database will take care of it with autovacuum. …
András Váczi's user avatar
2 votes

SELECT DISTINCT with another table

If I understand your requirements correctly, you want to join the other table on polyname and then get the max() of poly_version, like SELECT rule_name, rule_version, polyname, state, max(poly_versio …
András Váczi's user avatar
3 votes

Add 0 into array_agg if there is no matching data

For the first point, you can try this: COALESCE(array_agg(DISTINCT pr.position), '{0}'::integer[]) The same can be achieved by a CASE, too: CASE WHEN array_agg(id) IS NULL THEN '{0}'::integer …
András Váczi's user avatar
1 vote

Is there a way I can use currval() without selecting it more than once?

Try WITH vals (reportid, amount) AS ( VALUES (10, 40), (15, 29), (40, 4) ) INSERT INTO testschema.requestinfo (requestid, reportid, amount) SELECT currval('testschema.reque …
András Váczi's user avatar
1 vote
Accepted

Custom personal monitor sql by writing the .psqlrc file

Using psql variables with quotes is a bit tricky. As you noticed, they don't get substituted in certain positions, among other, between quotes. My only solution to this so far has been including t …
András Váczi's user avatar
4 votes
Accepted

Renaming a column in a PostgreSQL database table

You could try it yourself as well, but no: renaming a column won't break your foreign keys. Try this: CREATE TABLE a (a_id serial PRIMARY KEY); CREATE TABLE b (a_id integer REFERENCES a (a_id)); A …
András Váczi's user avatar
9 votes
Accepted

generate_series for multiple record types in postgresql

I usually solve such problems by setting up a table for all the possible data points (here the pests and dates). This is easily achieved by a CROSS JOIN, see the WITH query below. Then, as the finis …
András Váczi's user avatar
2 votes
Accepted

Does PostgreSQL write first to WAL and then to data files?

Your understanding is not correct. Specifies whether transaction commit will wait for WAL records to be written to disk before the command returns a "success" indication to the client means …
András Váczi's user avatar
13 votes

Where are database specific settings stored?

Database-level settings are not stored in any configuration file, but the pg_db_role_setting catalog, the only question is how to get them out there. As often in similar cases, psql can be of tremend …
András Váczi's user avatar

1
2 3 4 5
25
15 30 50 per page