Skip to content
Advertisement

Tag: postgresql

Round timestamp to 30 minutes interval to group by

Problem I want to group my data by currency, timestamp and show all type value like table of comparison with interval of 30 minutes, for now my created time is 1 minute or less different so if i group with created time it will still showing 4 rows cause of different timestamp, is there a way to round the timestamp

Generate random date into series [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 11 months ago. Improve this question

PSQL timestamp – how to include microseconds?

How can I create an SQL timestamp from an ISO timestamp that includes microseconds? e.g. select to_timestamp(‘2021-08-29T16:32:25.336239Z’,’yyyy-mm-ddThh24:mi:ss.usZ’) will result in 2021-08-29 16:32:25 – microseconds precision lost. Answer You can use ISO timestamps directly: The TIMESTAMP ‘YYYY-MM-DD HH:mm:ss.nnnnnn+offset’ is the standard ANSI SQL format, which PG supports, and they also support ISO8601 in addition to it, since the difference is minimal.

postgres syntax error on grant select on table

I have a query: But on running this: I get the following syntax error: without grant query its working fine. What am I missing here? Answer To specify the schema, use ON public.abc. The syntax IN SCHEMA public can only be used with ON ALL TABLES. Also, you have to separate CREATE TABLE and GRANT with a semicolon, as they

Arranging VARCHAR data into Columns in SQL

My data is in a SQL table in the following format (I have about 20 different answers per user_id): I would like to create a view in PostgreSQL where all the data is shown according to User ID Thank you! Answer It is great example of not relational data (the semantic depends on row number), although the data are saved

join two sql table as column

i have two tables as below: firsttable id cat_id name 1 2 name_01 2 2 name_02 3 1 name_03 4 3 name_04 5 3 name_04 secondtable id name 1 cat_01 2 cat_02 3 cat_03 my question is how can i create below table result? id(secondtable) name(secondtable) count(firsttable) 1 cat_01 1 2 cat_02 2 3 cat_03 2 Answer

Postgres transpose a row

I have a table which looks like the following :- I want to transpose it to the following form, in Postgres: I know I’m supposed to use the pivot operation to do this, but I can’t figure out the right syntax to get this done. Any help to get this done will be appreciated. Answer That would simply be: but

Advertisement