I try to list out the questions during working on Postgresql here for the future reference.
How to convert date string to timestamp in postgresql?
Use function TO_TIMESTAMP
|
|
How to return a string value from jsonb in Postgresql?
Use jsonb->>key
operator, be carefuly if you use jsonb->key
it will return back jsonb
type, not a string.
|
|
Can I extract the info from jsonb in postgresql?
jsonb_extract_path ( from_json jsonb, VARIADIC path_elems text[] ) → jsonb
Extracts JSON sub-object at the specified path. (This is functionally equivalent to the #> operator, but writing the path out as a variadic list can be more convenient in some cases.)
|
|
How to put log in stored procedures?
You need to change the config file postgresql.conf
and set log_min_messages = notice
, there are some options you can choose, check the config file.
IS NOT NULL work with composite type data
If you have a value something that is a composite type, for example a row of a table, something IS NOT NULL
is only true if none of the attributes of the composite are NULL.
check more details here
How to save 24hours time format
if you see some error like this Postgresql ERROR: hour "16" is invalid for the 12-hour clock
you could do this TO_TIMESTAMP(i_test_date ->> 'created_at', 'YYYY-MM-DD HH24:MI:SS')
to save the time as 24hours format